views:

189

answers:

2

I'm using the app engine locally, and sometimes the JS files are being cached between page refreshes, and it drives me crazy because I don't know if there's a bug in the javascript code I'm trying to write, or if the cache is acting up.

How do I completely disable cache for *.js files? Or maybe the question is, how to have it be smart, like based on last-modified date.

Thanks!

UPDATE- So it turns out Chrome Dev (for mac at least) has caching issues, going back to Chrome Beta fixes all this. The answers have still been helpful though, thanks

+3  A: 

Based on the docs, you can specify an app-wide cache expiration duration:

Unless told otherwise, web browsers retain files they load from a website for a limited period of time. You can define a global default cache period for all static file handlers for an application by including the default_expiration element, a top-level element. You can also configure a cache duration for specific static file handler. (Script handlers can set cache durations by returning the appropriate HTTP headers to the browser.)

default_expiration

The length of time a static file served by a static file handler ought to be cached in the user's browser, if the handler does not specify its own expiration. The value is a string of numbers and units, separated by spaces, where units can be d for days, h for hours, m for minutes, and s for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first loaded by the browser.

default_expiration is optional. If omitted, the default behavior is to allow the browser to determine its own cache duration.

...and if you want to specify the expiration on a directory-by-directory basis:

expiration

The length of time a static file served by this handler ought to be cached in the user's browser. The value is a string of numbers and units, separated by spaces, where units can be d for days, h for hours, m for minutes, and s for seconds. For example, "4d 5h" sets cache expiration to 4 days and 5 hours after the file is first loaded by the browser.

Try setting them to 0d0h or 1s and see if it disables caching entirely.

Jason Hall
I tried setting it to 0s, and now the headers do have this: `Cache-Control:no-cache` however Chrome (this is a chrome only app) is still caching stuff. Seems like the browser might be the issue.....
Infinity
+4  A: 

A common practice used by the major sites is to cache documents forever but include a unique identifier based on the release version or date into the url for the .js or .css call. For example:

<script type="text/javascript" src="static/util.js?version=20100310"></script>

This way you get optimum caching as well as always up to date files. The only trick is to figure out how to include an up to date version number in your url, which you can automate based on your deployment environment.

Parand