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.

General Questions

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

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

Requirements::javascript loading js files twice


Reply

6 Posts   1571 Views

Avatar
tv

18 July 2011 at 2:45am Community Member, 44 Posts

I am trying to use Requirements::javascript to load in my .js files. For some reason silverstripe is loading all the files twice any time I use Requirements::javascript.

Has anyone else experienced this?

Here is my code:

   function init() {
      $themePath = 'themes/' . SSViewer::current_theme() . '/';
      Requirements::javascript($themePath . 'js/JAIL.js');
      
      parent::init();
   }

I'm getting the same result when I try to use Requirements in page.php as well.

Thanks!

Avatar
swaiba

19 July 2011 at 4:39am Forum Moderator, 1796 Posts

2 things to try...

1) move the parent::init to the beginning of the function
2) add a Debug::show('test') to ensure that the code is only called once

Avatar
swaiba

19 July 2011 at 4:39am Forum Moderator, 1796 Posts

2 things to try...

1) move the parent::init to the beginning of the function
2) add a Debug::show('test') to ensure that the code is only called once

Avatar
tv

19 July 2011 at 9:18am Community Member, 44 Posts

thanks swaiba.

I added a Debug test and it seemed to confirm that Page_Controller was only being called once. I also added the parent::init call at the top of the function, but still having the same issue. Any files inserted into the page through the Requirements::javascript method are being added twice - Requirements::customScript, Requirements::javascript, etc. Oddly, Requirements::css is not exhibiting the same behavior.

All other elements of my footer are only being inserted once (</body>, </html>, etc) so I don't think it is a matter of including my Footer twice.

Any other thoughts?

Thanks again!

Avatar
tv

21 July 2011 at 2:21am Community Member, 44 Posts

Oddly enough, I removed my html5 <header> element in my header and replaced it <div id="header"> and that stopped the double inclusion of Requirements::javascript files.

Avatar
Innovatif

23 December 2011 at 5:27am Community Member, 4 Posts

See https://github.com/silverstripe/sapphire/pull/143 for fix.