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

linked javascript order


Reply


3 Posts   2216 Views

Avatar
marcink

Community Member, 89 Posts

14 April 2009 at 5:42am

hi,

in what order does ss link javascript files?
because in my page.ss i have:

<% require javascript(xxx/jquery-1.3.2.min.js) %>
<% require javascript(xxx/ui.accordion.js) %>

but when i test the page, ui.accordion.js is always linked bevor jquery...

thanks

Avatar
dfondente

Community Member, 15 Posts

28 July 2009 at 1:18pm

Can anyone provide insight into this? I'm having a problem with the javascript load order as well. I put my <% require javascript %> tag in my .ss file just before I need the functionality, but the included js file is being linked too early (it's being linked before jquery, which it depends on). So I can't use the library because it consistently loads before jquery.js.

Avatar
dfondente

Community Member, 15 Posts

29 July 2009 at 12:57pm

Edited: 06/08/2009 12:05pm

For the benefit of anyone else who has this problem:

Don't link to the javascript files from your templates. Instead, load them in the init() call in the relevant controller. For example:

public function init()
{
   Requirements::javascript('path/to/jquery.js');
   Requirements::javascript('path/to/library/that/requires/jquery/lib.js');
   parent::init();
}

That works for me, as now jquery is linked before the other libraries that depend on it.

UPDATE: This is not an all-purpose solution. This fixed one particular situation, but doesn't truly solve the underlying problem. If anyone can shed light on how to really control the load order it would be helpful.