Flavien
Flavien

Reputation: 73

How do Minify, mod_pagespeed... handle merging javascript files

Say that on page1.html I need mootools.js and main.js... I guess that these tools should generate one minified js file (say min1.js). Then on page2.html I need mootools.js, main.js AND page2.js... Do those tools serve min1.js (already cached by browser) and page2.js ? Or do they combine these 3 .js files and serve the resulting minified file which need to be fully cached again by the browser ?

Thank you

Upvotes: 3

Views: 2394

Answers (1)

Jon Adams
Jon Adams

Reputation: 25137

Assuming you are using the Apache module mod_pagespeed because you tagged the question with it but didn't mention if you are or not...

If you turn on ModPagespeedEnableFilters combine_javascript (which is disabled by default), it operates on the whole page. According to the documentation:

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

page1.html would combine mootools.js, main.js, and page1.js; and page2.html would be mootools.js, main.js, and page2.js.

To answer your question then, yes it will cache several copies of the repeated JavaScript files.

However,

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

If you leave this behavior on, and put the files spread out across paths that you want combined, you could keep them separate so that common scripts will be combined as one and individual scripts would be combined on their own. This would keep the duplication of large, common libraries down.

Upvotes: 1

Related Questions