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

Forums / Developing with Sitefinity / Jquery loaded more than once

Jquery loaded more than once

5 posts, 0 answered
  1. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    09 Jun 2010
    Link to this post
    I noticed that on some pages, more than one instance of jquery is being loaded, causing errors to occur (such as the WikiViewSingleItem, which is using <sfWeb:JsFileLink ID="JsFileLink1" runat="server" ScriptType="jQuery" />
    ).

    I'm already including jquery through my master page. Is there any way to prevent sitefinity from loading jquery a second time without mapping and editing every ascx that has a jsFileLink in it? This does not seem like a good practice, as two Sitefinity controls using a jQuery jsFileLink will encounter the same problem I'm currently having.

    If not, is there a way I can specify which jquery file to use? I do not like to link to a specific version of jquery (ie: jquery-1.2.6.min.js), I just link to jquery.js and anytime there is a new version I rename it as jquery.js.

    Thanks,
    Eric
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    09 Jun 2010
    Link to this post
    Hello Eric Wallace,

    You could remove the embedded script from the head tag. If you have several controls that uses embedded script resources you will not be able to identify which of them is the jQuery library and you have to map the external template.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    09 Jun 2010
    Link to this post
    Greetings Ivan,

    I do not understand what you mean by removing the embedded script from the head tag.

    Many of my controls use jquery, hence the reason it's included in my master page code-behind.

    Thanks,
    Eric
  4. Eric Wallace
    Eric Wallace avatar
    66 posts
    Registered:
    08 Oct 2009
    09 Jun 2010
    Link to this post
    Ok, I've removed it from the head tag. However, if I try to use any jquery in Page.ClientScript.RegisterStartupScript, it's throwing an error because the reference to the jquery tag is at the bottom of the page. Basically I HAVE to have jquery included in the head tag of my application. Is my only recourse to go into all the templates that have the jsfile link and disable or remove them?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    10 Jun 2010
    Link to this post
    Hi Eric Wallace,

    The options that I could come up are

    1. Remove the script controls from the header - the problem here is that you cannot identify which control is jsFileLink

    protected override void OnPreRender(EventArgs e)
      {
          base.OnPreRender(e);
     
          if (Page != null)
          {
              HideJQueryLinks(Page);
          }
      }
     
      private void HideJQueryLinks(Control parent)
      {
       for (int i = 0; i < Page.Header.Controls.Count; i++)
         {
             Control ctrl = this.Page.Header.Controls[i] as Control;
             if (ctrl is HtmlGenericControl && ((HtmlGenericControl)ctrl).Attributes["type"] == "text/javascript")
             {
                 {
                     parent.Controls.Remove(ctrl);
                 }
             }
          }
        }


    2. Map the templates and remove the JsFileLink

    JsFileLink adds a certain version of jQuery which is embedded resource and you have to override CreateChildControls and Render method of the control which is equivalent to removing  the controls from the templates.


    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Register for webinar
5 posts, 0 answered