Jump to:

1161 Posts in 2632 Topics by 409 members

Upgrading SilverStripe

SilverStripe Forums » Upgrading SilverStripe » Javascript (mystery) includes after body

Ask questions about upgrading SilverStripe to the latest version.

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

Page: 1
Go to End
Author Topic: 2806 Views
  • blueskies
    Avatar
    Community Member
    42 Posts

    Javascript (mystery) includes after body Link to this post

    With a fresh 2.3.0-rc2 install, I'm seeing the javascripts that I call with the Requirements in the init included _after_ the BODY tag. It's really weird and I am lost as to what the problem is. Is someone else seeing this with 2.3.0-rc2 or is it a mistake on my part?

    class HomePage_Controller extends Page_Controller {
       
       function init() {
             Requirements::javascript( "test/javascript/contentslider.js" );
             parent::init();
       }
       
    }

    The above results in the following in the source of our page:

    ...
    <body><script type="text/javascript" src="http://www.test.dev/test/javascript/contentslider.js?m=1221549972"></script><script type="text/javascript" src="http://www.test.dev/assets/base.js?m=1229700273"></script><script type="text/javascript" src="http://www.test.dev/sapphire/javascript/lang/en_US.js?m=1225402744"></script>

    ....

    An it's not only in the wrong place, but I never asked for base.js and en_US.js to be included?

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: Javascript (mystery) includes after body Link to this post

    The JS writing to the body is a speed improvement see http://developer.yahoo.com/performance/rules.html#js_bottom it should write it to the bottom unless it detects that the script needs it before hand I think.

    You can disable this feature and just include it via the head by setting this in your _config file Requirements::set_write_js_to_body(false);

    As for en_US.js / base.js I'm pretty sure these are included as part of i18n SilverStripe support.

  • blueskies
    Avatar
    Community Member
    42 Posts

    Re: Javascript (mystery) includes after body Link to this post

    Thank you for that! But it's still odd that the 2.3.0-rc2 is writing the Javascript right after the body tag, rather than to the end of it?

    Anyway, I've posted this info on the requirements page in the docs. Thanks again!

    2806 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.