javascript - How make browser update script file when manifest updates but allow caching? -


i have tried 2 different ways , both not work:

1. update manifest browser sees there's changes , updates

this updates files except javascript files. browser sees there's difference, downloads (including javascript files) uses cached version of javascript files.

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

this causes browser throw error , no longer cache anything. says 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 browsers not cache app offline use.

is there way around this?

i don't have sufficient perspective whether or not best practice, whenever our team makes javascript changes, increment query string variable @ end of path.

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

note v=10 @ end of src attribute. implies browser different file being retrieved, , therefore, circumvents cache.

i picked method following existing practice of co-workers.


Comments