Lojza Ibg
Lojza Ibg

Reputation: 658

Duplicated jquery definition using grails assets

If I have two independent assets that depends on jquery and use both in the same page the jquery js is included twice.

file1.js
//= require jquery
//= require plugin1.js

file2.js
//= require jquery
//= require plugin2.js

in HTML file:

<asset:javascript src="file1.js" />
<asset:javascript src="file2.js" />

How do I achieve that only one jquery is included?

Upvotes: 0

Views: 172

Answers (2)

Vladim&#237;r Duša
Vladim&#237;r Duša

Reputation: 11

It seems, that deduplication has been added in grails-asset-pipeline in version 3.0.0 https://github.com/bertramdev/asset-pipeline/commit/f8bd3d701a5fe14a30f5d89c6e8796f590d4643b#diff-0a3b83b6f81080c1f7f0486f9d5ae1a6

This feature is not yet documented, but according to the source code, we use follwing syntax which ensures, that duplicates are removed within same request:

    <asset:javascript src="myScript.js" uniq="true"/>

Upvotes: 1

James Kleeh
James Kleeh

Reputation: 12238

This is simply how asset pipeline works. If you have a page that needs both of those files, create a new manifest

file3.js

//= require file1.js
//= require file2.js

Then just include file3 on the page

<asset:javascript src="file3.js" />

Upvotes: 0

Related Questions