bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
194 stars 92 forks source link

Add feature for deduplicating javascript and stylesheets #205

Closed piis3 closed 6 years ago

piis3 commented 6 years ago

This adds an option to the asset tags in GSP called "uniq" which will deduplicate dependencies on a page. It is technically available on all of the asset tags, but is probably only useful for the javascript and stylesheet.

The idea here is that if you have javascript files A and B, both of which require file C, we don't want to write out a script tag for C twice, or have C included in two different bundles. Because this would make pre-bundling assets basically impossible, using the uniq="true" option disables bundling and will write out script/link tags for each dependency, but only once per page.

My use case for this is that my application's main page is broken into a bunch of different modules. These modules may or may not be included depending on the capabilities of the user that's logged in. This change lets each module declare its own dependencies without having to worry about the dependencies that other modules declare.

I'd be happy to help update docs if this change is accepted.