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.

Upgrading SilverStripe /

Ask questions about upgrading SilverStripe to the latest version.

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

Javascript (mystery) includes after body


Reply


3 Posts   2892 Views

Avatar
blueskies

Community Member, 42 Posts

20 December 2008 at 4:32am

Edited: 20/12/2008 4:34am

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?

Avatar
Willr

Forum Moderator, 5513 Posts

20 December 2008 at 2:12pm

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.

Avatar
blueskies

Community Member, 42 Posts

22 December 2008 at 11:17pm

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!