+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / ResourceLinks & script issues

ResourceLinks & script issues

3 posts, 1 answered
  1. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    10 Sep 2011
    Link to this post

    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>
    Which worked like a charm. Next up was to add jQuery.Validate and I tried the following:
    <sf:ResourceLinks ID="resourcesLinks" runat="server">
        <sf:ResourceFile JavaScriptLibrary="JQuery" />
        <sf:ResourceFile JavaScriptLibrary="JQueryValidate" />
    </sf:ResourceLinks>
    No luck and also not with:
    <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" />

    Stubborn as I am, I started to read the documentation which suggest using <sf:Resource> instead of <sf:ResourceFile> but apparently somewhere 4.0 and 4.2 the ‘Resource’ got totally scrapped and just replaced by ‘ResourceFile’.

    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 onto the SitefinityResources? So if we reference libraries through sf:resourcefiles they won’t get loaded double?

    Thanks,
    Jochem.


  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    14 Sep 2011
    Link to this post
    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
    }

    We have identified what makes the multple loading of jQuery and will try to fix this after the Sitefinity 4.2 SP release.

    In order to reference javascript libraries from resource files you can call them from their embedded location:
    <sf:ResourceFile Name="Telerik.Sitefinity.Resources.Scripts.jquery-ui-1.8.8.custom.min.js" />

    Or do something as bellow:
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);
        PageManager.ConfigureScriptManager(
            this.Page,
            ScriptRef.MicrosoftAjax |
            ScriptRef.MicrosoftAjaxWebForms |
            ScriptRef.JQuery |
            ScriptRef.JQueryValidate |
            ScriptRef.QueryString
            );
    }

    This allows to enumerate all built in script references and tell the current script manager what to include.

    Regards,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
    Answered
  3. Jochem Bökkers
    Jochem Bökkers avatar
    787 posts
    Registered:
    13 Aug 2007
    14 Sep 2011
    Link to this post
    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.
3 posts, 1 answered