performance - Minify,mod_pagespeed...如何处理合并javascript文件

标签 performance optimization mod-pagespeed

在 page1.html 上说我需要 mootools.js 和 main.js ......我猜这些工具应该生成一个缩小的 js 文件(比如 min1.js)。
然后在 page2.html 我需要 mootools.js、main.js 和 page2.js ......这些工具是否提供 min1.js (已经被浏览器缓存)和 page2.js ?或者他们是否结合了这 3 个 .js 文件并提供需要被浏览器再次完全缓存的缩小文件?

谢谢

最佳答案

假设您使用的是 Apache 模块 mod_pagespeed 因为您用它标记了问题但没有提及您是否使用...

如果你打开ModPagespeedEnableFilters combine_javascript (默认禁用),它在整个页面上运行。根据documentation :

This filter generates URLs that are essentially the concatenation of the URLs of all the CSS files being combined.



page1.html 将结合 mootools.js、main.js 和 page1.js; page2.html 将是 mootools.js、main.js 和 page2.js。

那么,要回答您的问题,是的,它会缓存重复的 JavaScript 文件的多个副本。

然而,

By default, the filter will combine together script files from different paths, placing the combined element at the lowest level common to both origins. In some cases, this may be undesirable. You can turn off the behavior with: ModPagespeedCombineAcrossPaths off



如果您保留此行为,并将文件分散在您想要组合的路径中,您可以将它们分开,以便将公共(public)脚本组合为一个,而单独的脚本将自行组合。这将减少大型通用库的重复。

关于performance - Minify,mod_pagespeed...如何处理合并javascript文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6865402/

相关文章:

java - 在Java中将大对象作为参数传递是否效率低下?

javascript - : redundant HTML layouts, 和不必要的 JavaScript 执行哪个更可取?

mysql - Rails 3 - 将多个计数转换为单个查询 - OrderedHash

c++ - 编译器是否优化了对虚方法的非多态调用?

mod-pagespeed - 我在页面优化时遇到 mod_pagespeed 图像重命名问题

java - 以高效的方式计算字符串中出现的字符数?‽?

python - 为什么嵌套时不添加函数的速度测试? (Python)

matlab - 请求的函数输出参数

linux - sudo dpkg -i mod-pagespeed-*.deb 给出 "not a debian format archive"错误

wordpress - Nginx url 重写 WordPress 与 ModPageSpeed 冲突