Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » Requirements::javascript loading js files twice

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

Page: 1
Go to End
Author Topic: 1428 Views
  • tv
    Avatar
    Community Member
    43 Posts

    Requirements::javascript loading js files twice Link to this post

    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!

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Requirements::javascript loading js files twice Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1769 Posts

    Re: Requirements::javascript loading js files twice Link to this post

    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

  • tv
    Avatar
    Community Member
    43 Posts

    Re: Requirements::javascript loading js files twice Link to this post

    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!

  • tv
    Avatar
    Community Member
    43 Posts

    Re: Requirements::javascript loading js files twice Link to this post

    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.

  • miiihi
    Avatar
    Community Member
    4 Posts
    1428 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.