More in this section

Forums / Developing with Sitefinity / Is jQuery loaded in scriptresource.axd standard?

Is jQuery loaded in scriptresource.axd standard?

4 posts, 0 answered
  1. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    10 Sep 2009
    Link to this post
    Hi There,

    I've noticed that the jquery (1.3.2) lib gets loaded in a ScriptResource.axd by Sitefinity. However, if I try to use jQuery somewhere on the page, in a location after this axd is loaded, it doesn't work. An example is $(document).ready(function(), I get the following error "Property '$' of object [object global] is not a function" , which makes me think that the libary that Sitefinity is loading has been modified in some way (are you using var $j = jQuery.noConflict(); somewhere, if so what is the var name being used?). The only way for me to get this to work is to indclude jquery.js file manually, so it's actually getting loaded twice. 

    So is there a way to use the jQuery lib that's being loaded by Sitefinity or to tell it not to load it so that he manually added one is used instead?

    Thanks in advance for any help.
    Cheers,
    Phill


  2. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    11 Sep 2009
    Link to this post
    Hi Phill Hodgkinson,

    Thank you for contacting us.

    Yes, we are using jQuery sometimes and this is the reason why you see it sometimes in the ScriptResources. We are not changing any of the variables though. Another thing is that jQuery is also built in Telerik.Web.UI, but it is hidden, uses different variables and should not make problems.

    If you want to use jQuery with Sitefinity, please take a look at the following blog post: How to use jQuery and other JavaScript Libraries in Sitefinity. Then you can use the default variables and methods, that jQuery provide. 

    I hope this helps.

    Sincerely yours,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Phill Hodgkinson
    Phill Hodgkinson avatar
    362 posts
    Registered:
    10 Nov 2004
    11 Sep 2009
    Link to this post
    Hi Georgi,

    I'm already loading jquery as per the instructions in the post you required. My question was more related to why can't I use the version that is loaded by Sitefinity, and now you're telling me there's yet another copy being loaded by Telerik.Web.UI. So now if I want to use jquery in my site the library possibly gets loaded 3 times! I'm using the min version which is only 56k but it still seems crazy to have to load this 56k 3 times. Is there no way to set a config setting that tells both Sitefinity and Telerik.Web.UI to not load it and use externally provided file? It just seems extrememly inefficient to me is all. Especially if there's a new version of jquery out that I want to run then there's possibly 2 - 3 different versions of the same lib too!

    Cheers,
    Phill
  4. Katia
    Katia avatar
    194 posts
    Registered:
    01 Jul 2016
    14 Sep 2009
    Link to this post
    Hello Phill Hodgkinson,

    Please read ASP.NET Ajax Controls and jQuery blog post. I think it will answer your question how to use jQuery that comes with Rad Controls.

    In brief, first your need to include jQuery. In your master page change Script Manager with Rad Script Manager and add a ScriptReference pointing to jQuery.js.

    <telerik:RadScriptManager runat="server" ID="RadScriptManager1"
        <Scripts> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
        </Scripts> 
    </telerik:RadScriptManager> 

    There are two ways to use jQuery after you have added it.

    An easy workaround to enable the $ alias
    <script type="text/javascript"
    window.$ = $telerik.$; 
    </script> 

    The recommended way of using jQuery:
    <script type="text/javascript"
    (function($) { 
        $(document).ready(function() { 
                alert("Hooray! The document is ready!"); 
            } 
        ); 
    })($telerik.$); 
    </script> 


    Please let us know if you need further help.

    Sincerely yours,
    Katia
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered