This project is read-only.

Included scripts appearing out of order

Topics: Customizing Orchard, Writing themes
Nov 1, 2012 at 10:15 PM
Edited Nov 1, 2012 at 10:16 PM


I'm including jQuery and jQuery-UI in my layout like this: 




But they're appearing in a different order on the page and throwing errors


<script src="/blog/Modules/Orchard.jQuery/Scripts/jquery-ui.min.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="/blog/Core/Shapes/Scripts/html5.js" type="text/javascript"></script>
<meta content="Orchard" name="generator" />
<meta content="IE=edge,chrome=1" name="X-UA-Compatible" />
<script src="//" type="text/javascript"></script>

How do I get them to show up in the same order as I included them in?


Nov 1, 2012 at 10:34 PM

I used the path to Microsoft's jQuery on their CDN and it worked. 

It seems to be an issue with the names of Google's version compared to the name of Microsoft's version. Microsoft's uses a folder to keep the version number while Microsoft has the version in their file name. 

These includes kept the 2 files in the same order

There still is an issue with these 2 includes being placed above the meta data though (after the path is changed to something local), out of the order of the rest of the includes. Is there a way around this? 

Nov 2, 2012 at 1:52 AM

So with the Microsoft's CDN you called the Include statement in the same order? I think you should file a bug. Meanwhile you could override Document.cshtml and include your scripts there without using the Script object. Alternatively, you could define a ResourceManifestProvider class and define the scripts from there, setting one script as a dependency for the other. Then you can use Script. Require one script, which will automatically include any dependent scripts.

Nov 2, 2012 at 1:53 AM

Could you try reversing the include statements, both for Google's as well as for Microsoft's and see what happens?

Nov 2, 2012 at 11:08 PM

I've just included them both from Microsoft and that puts them both at above the html5.js include. All the includes should be output in the same order as in the code shouldn't they? 

If I include them from Microsoft, they show up before the html5.js include (after having the path changed to local because it matches the CDN value in the jQuery ResourceManifest.cs file, I think) . If I include them from Google they appear after the html5.js include. 

And something more that is possibly related to my issue above:

Including jQuery with:


Results in 

<script src="/blog/Modules/Orchard.jQuery/scripts/jquery.js" type="text/javascript"></script>

and jquery.js doesn't exist. Not sure if this is a bug or I've got something set up wrong. 

Nov 4, 2012 at 2:51 AM

Could you try it with a fresh new Orchard install (1.6) and see if you can reproduce this issue? If so then please file a bug with repro steps so we can verify and fix. Thanks.

Nov 16, 2012 at 9:18 AM
Edited Nov 16, 2012 at 9:19 AM

I don't know if Ross has filed a bug for this, but I'd like to also say that I have experienced a similar issue.

I am using Orchard 1.6, and my theme's layout.cshtml uses 4 JS files. The first one to be included is jQuery, as the rest of the scripts rely on it. I started to get JS errors on my pages, and traced it down to the jQuery library being included on the page after the rest of the scripts. I appended .AtHead() to the Script.Require() for jQuery as a way to force that script to appear in the head whilst all the rest would appear at the foot of the page.

Interestingly, when I removed .AtHead(), the scripts were included in the correct order again. I couldn't reproduce the issue (and still can't) so I didn't file a bug at the time.


Here are my Include/Require statements:

Nov 16, 2012 at 6:02 PM

Sounds like the order is not deterministic then. I'd file a bug with a repro if there is n't one yet, mentioning that the order is not deterministic and that it may or may not work.