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.

Template Questions

Javascript goes to the wrong place in the body


Reply

3 Posts   280 Views

Avatar
thany

25 January 2014 at 3:31am Community Member, 6 Posts

Javascript should be included at the bottom of the page. For me, it gets included at an aribrary place in the page. This is wrong, and it breaks the javascript. In Requirements.php it says:

// If your template already has script tags in the body, then we put our script
// tags just before those. Otherwise, we put it at the bottom.

WTF.
Javascript should go to the bottom! Always!

There may well be a google analyitcs script, which is required to go to the top of the body. If I have that, then how to hell do I get script to the bottom??

Avatar
kinglozzer

25 January 2014 at 4:08am Community Member, 146 Posts

Hi thany,

This has been documented and fixed (https://github.com/silverstripe/silverstripe-framework/pull/2684) and the ability to force JS requirements to the end of your HTML will be included in the next SilverStripe release (3.1.3).

Loz

Avatar
thany

25 January 2014 at 4:15am Community Member, 6 Posts

I just changed the Requirement.php to look for a special tag in the HTML, so at least it will work for me. I made it look for "<javascriptIncludeSpot>". Could be anything, but it works like a charm. It's much better than looking for the </body> tag, because it is optional.