Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Requirements::customScript loads javascript twice

Go to End

3 Posts   1381 Views


Community Member, 33 Posts

7 September 2013 at 3:07am

How do I prevent Requirements from loading scripts twice?

When using Requirements::customScript to load javascript close to rendering, as described here the script is added to the end of the HTML twice. This causes any triggers to be fired twice.

I found one forum post which says double loading was fixed in version 2.4
This was slightly different as it was loading in the <head> and <header>, rather than twice at the end of the <body>

Another forum post
which says a similar issue was fixed in the SS 3.1. There is no SS 3.1 on the downloads page.

On a side note, I find the current search function, which appears to be embedded Google results, frustrating compared to the old forum search. The previous setup gave much more targeted results. One could get either specific forum search results using the internal search, or use Google as a second method.


Community Member, 344 Posts

7 September 2013 at 3:26am

Dunno what you're actually doing, maybe you've the same script twice in your code.

However you can try the second parameter $uniquenessID of customScript().

Requirements::customScript("alert('no one');", 'myUniqueID');
Requirements::customScript("alert('me');", 'myUniqueID');


Community Member, 33 Posts

7 September 2013 at 3:34am

Hi Devlin,

Thanks for your quick reply!

I found the undocumented $uniquenessID digging through the source code after I posted. I put a random number in the string and it worked. It's probably smart to use a string that's descriptive of the script so one doesn't accidentally use the same ID twice for different scripts.