ResourceLinks & script issues
I found myself developing a project independent widget which takes a dependency on jQuery and jQuery.Validate. Since I want to use it across different projects I wanted to include those two libraries in case a user ever drags them on a page when jQuery & jQuery.Validate aren’t loaded.
First I referenced them manually, but then I remembered Gabe Sumner’s post on ResourceLinks and thought it would be a better idea to reference the same files as Sitefinity uses.
So for round 1 I used the following:
<
sf:ResourceLinks
ID
=
"resourcesLinks"
runat
=
"server"
>
<
sf:ResourceFile
JavaScriptLibrary
=
"JQuery"
/>
</
sf:ResourceLinks
>
<
sf:ResourceLinks
ID
=
"resourcesLinks"
runat
=
"server"
>
<
sf:ResourceFile
JavaScriptLibrary
=
"JQuery"
/>
<
sf:ResourceFile
JavaScriptLibrary
=
"JQueryValidate"
/>
</
sf:ResourceLinks
>
<
sf:ResourceFile
JavaScriptLibrary
=
"JQuery.Validate"
/>
<
sf:ResourceFile
JavaScriptLibrary
=
"JQuery.Validate.min.js"
/>
<
sf:ResourceFile
Name
=
"Telerik/Sitefinity/Resources/jquery.validate.min.js"
Static
=
"True"
/>
<
sf:ResourceFile
Name
=
"Telerik/Sitefinity/Resources/Scripts/jquery.validate.min.js"
Static
=
"True"
/>
So first blond question is…
Is there a way to reference the Javascript libraries which are in mentioned in the scriptreferences? Or are these just cosmetics and only jQuery and Mootools being operational? Or should I just not be doing this on a Saturday evening...
---
And it still works, but I’m going way overboard on the scriptloading. I know, I’ve complained about it before but…
Finally I gave up and just left jQuery.Validate out of it. All was working great on my empty template page, so I thought I’d try and drag it onto a ‘designed’ masterpage.
I’ve got a custom designed masterpage, which takes a dependency on jQuery. Me being a nice guy, I first do a quick check to see if jQuery’s already being loaded before loading it. Now if the Radcontrols are a bit slow on the loading, first my jQuery from my masterpage gets loaded. Then the jQuery from the Radcontrols on the page get loaded and finally my widget’s sf:resourcefile jQuery gets loaded.
I’m a big fan of jQuery, but loading it 3 times is a tad too much even for my taste. And if I ignore my dependency, I’m sure somewhere along the road it’ll come back and bite me.
---
I know it’s a RadControls issue, we’ve been over this sometimes before but I’m starting to move snippets & widgets from project-tailored over to generic reusable widgets and unsure what to do… wait to see if things change on your end, or should I build in extra checks to circumvent these things.
So I was wondering, even if you don’t guys comment on future ‘roadmap’, are you guys sitting down with the RadControls team and discussing removing the jQuery inclusion from the controls? I understand something like this isn’t solved with the flick of a switch, but would love to know if it’s being discussed 1/2/3 versions down the road.
If not, can/will you guys consider adding a conditional check to it?
You’re embedding jQuery already in your own ‘version’ (just to add the $Telerik) but can’t you extend that check? And if not that, will you guys consider adding something like YepNope.js (standalone part of Modernizr, which Microsoft self these days is taking a dependency on) to the SitefinityResources? So if we reference libraries through sf:resourcefiles they won’t get loaded double?
Thanks,
Jochem.
Hi Jochem,
jQueryValidate cannot be inserted in as jQuery in the resource links, because it is not part of the automatically embedded libraries. Here is a list of those libraries:
///<
summary
>
/// Enumeration of libraries that can be embedded automatically.
///</
summary
>
public enum JavaScriptLibrary
/// <
summary
>
/// No library
/// </
summary
>
None,
/// <
summary
>
/// jQuery JavaScript library
/// </
summary
>
JQuery,
/// <
summary
>
/// Mootools JavaScript library
/// </
summary
>
Mootools,
/// <
summary
>
/// prototype JavaScript library
/// </
summary
>
Prototype,
/// <
summary
>
/// JQuery FancyBox
/// </
summary
>
JQueryFancyBox
<
sf:ResourceFile
Name
=
"Telerik.Sitefinity.Resources.Scripts.jquery-ui-1.8.8.custom.min.js"
/>
protected
override
void
OnPreRender(EventArgs e)
base
.OnPreRender(e);
PageManager.ConfigureScriptManager(
this
.Page,
ScriptRef.MicrosoftAjax |
ScriptRef.MicrosoftAjaxWebForms |
ScriptRef.JQuery |
ScriptRef.JQueryValidate |
ScriptRef.QueryString
);
Hey Radoslav,
Gotcha! Thanks for sharing... I guess Saturday evening was a bad evening after all, can't imagine I missed the name with . attempt but tried it for library... Will put the dependency back in.
Jochem.