简体   繁体   English

Javascript缩小和HTML5清单

[英]Javascript minification and HTML5 manifest

We have created a HTML5 application which also works in offline mode. 我们创建了一个HTML5应用程序,该应用程序也可以在离线模式下使用。 The HTML element includes the manifest attribute and our manifest includes all necessary files to be able to use the application offline. HTML元素包括清单属性,我们的清单包括所有必需的文件,以能够离线使用该应用程序。 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). 我们正在尝试找到一种自动缩小JavaScript文件的方法,但又需要一个有效的清单文件(缩小后无需手动编辑清单文件)。 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. 通常,在使用缩小的javascript文件时,最好在文件名中使用版本号或querystring变量之类的内容,以确保加载了缩小的javascript文件的新版本,但这在与清单结合使用时效果不佳该文件不支持更改查询字符串变量或其他文件名。

We have tried AjaxMin and SquishIt, but weren't able to get this working. 我们已经尝试过AjaxMin和SquishIt,但无法使其正常工作。 Do you guys have any ideas or working solutions for making this combination work? 你们有什么想法或可行的解决方案来使这种组合有效吗?

Our HTML: 我们的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. 您的新JS文件也是如此。 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). (*)重新下载时,浏览器将发送Last-Modified和/或E-Tag标头,因此如果文件未修改(减少带宽使用),则服务器可以返回304。 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. 另外,某些浏览器也会尊重expires标头,因此请发送不久或更远的expire标头,因为使用appCache时,基于expire标头的缓存是无用的。

Also note that firefox will guess a expires value based on the last-modified header if no expires is send. 还要注意,如果没有发送过期消息,firefox将根据最后修改的标头猜测过期值。 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). 如果文件有一段时间没有更改,并且您正在使用appcache,则没有办法强制firefox重新下载该文件,除非更改了文件名(几乎弄丢了我的头脑,试图弄清楚为什么FX不更新)一些文件)。

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? 现在可以使用新的JS,或者在无法使浏览器使用新文件的地方?

You have some build process or release process to minify your JavaScript, right? 您有一些构建过程或发布过程来最小化JavaScript,对吗? 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. 在构建工具(make,rake,ant或其他工具)重建新的精简JavaScript之后,它还需要生成一个指向新JavaScript文件的清单文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM