OrchardGallery theme: flaw when using Google CDN

Jul 11, 2011 at 5:31 PM


The recent commits for the gallery theme (https://bitbucket.org/kevinkuebler/orchard-gallery-theme/changesets) changed the jQuery and jQueryUI library to be included from Google CDN.

However, the current implementation has one flaw, in Layout.cshtml the library is included as follows:

Script.Require("jQueryUI_Core").Define(x => x.SetUrl(http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.10/jquery-ui.min.js));


This means that the Url is overridden to point to the CDN, but only if "Resource Debug Mode" is "disabled" in Admin --> Settings --> Resource Debug Mode. The default value when using a freshly checked out copy of Orchard Gallery is "Use web.config settings", which translates to "enabled" during debugging in Visual Studio.

The problem is, that jQueryUI_Core (as initially defined by the Orchard.jQuery module) only contains the Core jQuery UI file (jquery.ui.core.js). The CDN version however includes all widgets, so the site behavior breaks when jQueryUI_Core falls back to the default setting/file during debugging. This breaks Views that use widgets and rely on the CDN version to be present. For example, Views/Orchard.Gallery/ManagePackageOwners/Index.cshtml and Views/Orchard.Gallery/UploadPackageLogoAndScreenshots/Index.cshtml use the Dialog widget, but only define Script.Require("jQueryUI_Core");.

This can be fixed by setting the second parameter in the Script.Require() call in Layout.cshtml to point to the CDN too, so that the link in debug mode doesn't fall back to the local version. Alternatively, a Script.Require("jQueryUI_Dialog"); could be added to the Views that break during debugging, but this would include the widget twice when the CDN version is used after deployment (not desirable). 

Side note: I've been digging through the codebase and found a .SetCdn() method in the ResourceDefinition class, is there a reason why it's not being used?

Let me know what you think,

Jul 11, 2011 at 5:56 PM

I made this change, sorry if it broke in debug. Your fix is valid, I will add it. To answer your question about SetCdn, it's that it can't be called from the view like this, it could be called from the code, and I didn't want to add any code for that, as it's a theme only. Might change with next version of Orchard.

Jul 11, 2011 at 6:12 PM

Thanks for the fast reply ;-)

I am currently building a website on top of the gallery project and so far it was a very smooth experience, thanks to the modular architecture of Orchard.

As the site will be multi-language, I modified the theme and added T() calls where appropriate and localized it into German. Are you interested in the changes?