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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Requirements - changing JS loading order.


4 Posts   1629 Views


28 April 2009 at 3:58pm Community Member, 712 Posts

I've come across an issue where the order in which prototype and jQuery are loaded cause issues. In the CMS, prototype is called first, then jQuery kindly lets it do its thing by running with noConflict.

However, I'm trying to use a TabSets outside of the CMS and for some reason unknown, jQuery is appearing before prototype. This causes prototype to semi-fail. Validators don't work properly, I get errors like "$ is not a function" etc. I guess it isn't surprising considering that TabSet loads the entire jQuery library just so it can use livequery, but uses prototype for all it's internal logic in (tabstrip.js).

I mean, surely whoever wrote this in TabSet.php felt a little bit dirty :D

   public function FieldHolder() {
      Requirements::javascript(THIRDPARTY_DIR . "/loader.js");
      Requirements::javascript(THIRDPARTY_DIR . "/prototype.js");
      Requirements::javascript(THIRDPARTY_DIR . "/behaviour.js");
      Requirements::javascript(THIRDPARTY_DIR . "/prototype_improvements.js");
      Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery.js");
      Requirements::javascript(THIRDPARTY_DIR . "/jquery/jquery_improvements.js");
      Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/livequery/jquery.livequery.js');
      Requirements::javascript(THIRDPARTY_DIR . "/tabstrip/tabstrip.js");
      Requirements::css(THIRDPARTY_DIR . "/tabstrip/tabstrip.css");
      return $this->renderWith("TabSetFieldHolder");

Anyway, is there any way for force javascript requirements to appear in a particular order. Since prototype refuses to play nicely, it is up to jQuery to save the day by loading second. Any tips appreciated.



28 April 2009 at 4:02pm Community Member, 712 Posts

By the way, I found out it was the loading order by copying the generated source into a static page, then swapped the scripts around. Simply moving prototype before jquery fixes the problem.


28 April 2009 at 4:13pm Community Member, 712 Posts

Ok, found where jQuery was being loaded and preceded it with a requrements all for prototype. So now I have to load prototype every time I want to juse jQuery, on the off-chance that something else will try to load prototype later. Makes jQuery seem a little pointless :/


11 May 2009 at 12:50pm Community Member, 55 Posts

Could you post your code for this? I'm having real problems getting jquery and prototype to play nicely.