Jump to:

3445 Posts in 1031 Topics by 872 members

Template Questions

SilverStripe Forums » Template Questions » Javascript goes to the wrong place in the body

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

Page: 1
Go to End
Author Topic: 272 Views
  • thany
    Avatar
    Community Member
    6 Posts

    Javascript goes to the wrong place in the body Link to this post

    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??

  • kinglozzer
    Avatar
    Community Member
    142 Posts

    Re: Javascript goes to the wrong place in the body Link to this post

    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

  • thany
    Avatar
    Community Member
    6 Posts

    Re: Javascript goes to the wrong place in the body Link to this post

    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.

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