6

I have tried two different ways and both do not work:

1. Update the manifest so browser sees there's changes and updates

This updates all files except JavaScript files. The browser sees there's a difference, downloads everything (including JavaScript files) but uses the cached version of the JavaScript files.

2. Send no-cache headers (see code below) to stop caching of script files

This causes the browser to throw an error and no longer cache anything. It says an ApplicationCache error occurred.

The no-cache code:

<filesMatch "\.(js)$">
    FileETag None
    <ifModule mod_headers.c>
        Header unset ETag
        Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
        Header set Pragma "no-cache"
        Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
    </ifModule>
</filesMatch>

The above makes all browsers not cache the app for offline use.

Is there a way around this?

Dan D.
  • 73,243
  • 15
  • 104
  • 123
Don Rhummy
  • 24,730
  • 42
  • 175
  • 330
  • First note, the application cache seems to be deprecated (but still the only solution): https://developer.mozilla.org/en-US/docs/Web/HTML/Using_the_application_cache How do you know that the browser downloads the scripts? I find it hard to believe it loads successfully but does not use it. It might give a "304 - Not modified" status. – msoft Sep 30 '15 at 08:32

1 Answers1

1

I don't have sufficient perspective to say whether or not this is a best practice, but whenever our team makes Javascript changes, we increment a query string variable at the end of the path.

<script type="text/javascript" src="/path/to/script.js?v=10"></script>  

Note the v=10 at the end of the src attribute. This implies to the browser that a different file is being retrieved, and therefore, circumvents the cache.

I picked up this method by following existing practice of co-workers.

Thew
  • 61
  • 9
  • That's not a bad solution, and I'd have it automatically update the manifest as well (because it has to match in the manifest) – Don Rhummy Sep 30 '15 at 16:50