The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

JasonStoltz (2) [Avatar] Offline
#1
First off, some feedback... the book is great so far. We've been following along chapter by chapter while we develop a third-party js api for our site partners. So far the advice has been solid and all especially relevant. Alas, i think our api will need to be completed before the final chapters of this book are completed smilie ... so hopefully we don't missed anything important!

Anyway, here's a discussion we're having that I am wondering if you plan to touch on: For the initial script that is loaded, "Widget.js", how do you go about defeating browser caching when changes need to be made to that script? Are there recommended cache control settings that sort of balance performance and also allow for change? So essentially what I'm asking is: How do we update our javascript API without asking the users to update their js reference?

We are trying out a set up where we have our initial script, which is cached indefinitely. This is a light-weight script that simply makes a server call to retrieve a list of versioned files to include, and includes them all dynamically, all of which are cached indefinitely. So when a script needs to change, we just rev the script version, and include the latest version of the script, which defeats caching. But I am still concerned with having that first, initial script cached indefinitely.

Anyway, just wondering if you'll include any recommendations or discuss this topic at all.

Message was edited by:
JasonStoltz
benvinegar (68) [Avatar] Offline
#2
Re: Updates to Widget.js -- cache control?
Hey Jason,

Great question.

At Disqus, we actually *don't* use expire headers to cache our initial script. All the remaining scripts, are, however. We do this for flexibility: we can substitute out this script at a later date without much trouble.

A quick glance at some other libraries seems like this is the case: Facebook's JS SDK uses expires headers, but only for about 8 hours in the future. Twitter @Anywhere looks like they set roughly the same headers as us.

http://connect.facebook.net/en_US/all.js
http://platform.twitter.com/anywhere.js

So, I guess that's standard practice. To be honest, if your initial script file is tiny (as yous ay it is), and you use a CDN like Akamai, having to ping the server or worst-case re-download the file isn't such a big deal. Facebook might have it right by setting a short-lived expires header.

Hope this is helpful. And thanks for your feedback about the book. Feel free to ping me or write on the forums if you've got any more questions.
JasonStoltz (2) [Avatar] Offline
#3
Re: Updates to Widget.js -- cache control?
Yes, thanks Ben. This is very helpful.