Jump to:

3444 Posts in 1030 Topics by 871 members

Template Questions

SilverStripe Forums » Template Questions » [SOLVED] Why does calling Requirements::javascript include other core javascript files?

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

Page: 1
Go to End
Author Topic: 2177 Views
  • Ryno in Stereo
    Avatar
    Community Member
    8 Posts

    [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    Environment: Windows XP SP3 XAMPP, PHP 5.2.8, Apache 2.2.11
    SilverStripe version: /branches/2.3

    In my customised version of mysite/code/Page.php in the init() method, whenever I make a call to Requirements::javascript, the following always end up being included in the outputted HTML.

    <script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/behaviour.js?m=1231497686"></script>
    <script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/prototype.js?m=1231381869"></script>
    <script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/i18n.js?m=1231381787"></script>
    <script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/lang/en_US.js?m=1231381787"></script>
    <script type="text/javascript" src="http://development.surferscentury.com.au/themes/surferscentury/js/jquery-1.3.1.min.js?m=1232688508"></script><script type="text/javascript" src="http://development.surferscentury.com.au/themes/surferscentury/js/swfobject.js?m=1232617897"></script><script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/behaviour.js?m=1231497686"></script><script type="text/javascript" src="http://development.surferscentury.com.au/jsparty/prototype.js?m=1231381869"></script><script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/i18n.js?m=1231381787"></script><script type="text/javascript" src="http://development.surferscentury.com.au/sapphire/javascript/lang/en_US.js?m=1231381787"></script><script type="text/javascript">//<![CDATA[
                Behaviour.register({
                   '#switchView a' : {
                      onclick : function() {
                         var w = window.open(this.href,windowName(this.target));
                         w.focus();
                         return false;
                      }
                   }
                });

                function windowName(suffix) {
                   var base = document.getElementsByTagName('base')[0].href.replace('http://','').replace(/\//g,'_').replace(/\./g,'_');
                   return base + suffix;
                }
                window.name = windowName('site');

    //]]></script>

    Why is this?

    Calling Requirements::clear() doesn't work because as soon as I include any javascript via the Requirements:javascript() method, I cannot stop the above output?

    How can I stop this happening as I want control over what JavaScript files do and do not display.

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    Do you mean that the <script></script> tags are visible on the screen?

    Check whether they are in side the <head></head> section

  • ajshort
    Avatar
    Community Member
    244 Posts

    Re: [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    Nivanka - I think you misunderstood the question.

    Ryno: These JS files are included in order to enable javascript translation. However, if you don't need any of this, you can manually block each javascript file in your Page_Controller->init() method. Just add something like this to block a javascript file:

    Requirements::block('jsparty/behaviour.js');

    and so on for each file you don't need.

  • Ryno in Stereo
    Avatar
    Community Member
    8 Posts

    Re: [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    Thanks ajshort, that's exactly what I needed to know!

  • Nivanka
    Avatar
    Community Member
    395 Posts

    Re: [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    Ah yes Ajshort, I thought something else.

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: [SOLVED] Why does calling Requirements::javascript include other core javascript files? Link to this post

    I posted on the developer forum about this - I'm not a fan. Even if there is no translatable content on the page, prototype and i18n are included. We should not have to explicitly block javascript files from loading if we're not using them.

    It also adds another upgrade step, more baggage to the root page type and so on.

    Hamish

  • Ingo
    Avatar
    Forum Moderator
    801 Posts
    2177 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.