Javascript minification and HTML5 manifest
We have created a HTML5 application which also works in offline mode. The HTML element includes the manifest attribute and our manifest includes all necessary files to be able to use the application offline. We are trying to find a way to minify our javascript files in an automated way, but also have a working manifest file (without the need for manually editing the manifest file after minification). Mostly when working with minified javascript files it is best to use something like a version number in the file name or a querystring variable to be sure new versions of the minified javascript files are loaded, but this doesn't work well when combined with a manifest file which doesn't support changing querystring variables or different file names.
We have tried AjaxMin and SquishIt, but weren't able to get this working. Do you guys h开发者_如何学编程ave any ideas or working solutions for making this combination work?
Our HTML:
<html manifest="app.manifest">
Our manifest:
CACHE MANIFEST
NETWORK:
data
CACHE:
scripts/application/application.js
scripts/application/database.js
scripts/application/knockout.extensions.js
scripts/application/main.js
scripts/application/models.js
scripts/application/prototype.extensions.js
etc...
Thanks!
If you want to push an update you only need to change the manifest by one or more bytes. Most people use a comment with a version number.
#version 0.1
When the browser shows the cached the page it download the manifest in the background. If it is changed it will re-download* all files in the manifest. So also your new JS file. So this is all you need to do to trigger downloading the new file. Once everything is downloaded correctly the new files will be used the next time you load the page.
(*) when re-downloading the browser will sent the Last-Modified and/or E-Tag headers so the server can return a 304 if the file has not modified (to reduce bandwidth use). Also some browser will respect the expires headers, so send expire headers that are not to far into the future, or even better that are in the past, since caching based on the expires header is useless when using appCache.
Also note that firefox will guess a expires value based on the last-modified header if no expires is send. If the file hasn't changed for a while, and you are using appcache, there is no way to force firefox to re-download that file, except changing it's filename (almost lost my sanity trying to figure out why FX didn't update some files).
Not sure what you minification problem is. Does the new JS now work, or where you not able to get the browser to use the new file?
You have some build process or release process to minify your JavaScript, right? Now you have to make re-generating a newer version of manifest part of that process. After your build tool (make, rake, ant or whatever) rebuild the new minified JavaScript, it also needs to generate a new manifest file pointing to the new JavaScript files.
精彩评论