Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is jQuery "reloading" itself (via Ajax) after I have included it myself?

Tags:

jquery

I'm seeing some strange behaviour on a web page... I have included jQuery (and jQuery UI) using regular script tags. When the page loads I see that the file is loaded (from the local browser cache as there are far-future Expires headers on the file).

However, it seems that jQuery itself initiates a new network request to fetch itself again, including a random parameter value which causes the file to download (ie not use the cached version).

A screenshot from Chrome's network tab:

jQuery loading itself... ?

This is very strange... what is happening here ?

UPDATE: The code that is triggering this behaviour is the following:

   $(window).load(function() {
     $("#t20ContentRightWrapper").toggle("slide", { direction: "right" }, 400);
   });

If I change it to this instead, the "double-loading" goes away:

   $(window).load(function() {
       $("#t20ContentRightWrapper").toggle("fade", 400);
   });

So basically, when I'm using the "slide" animation, jQuery and jQuery UI get reloaded with extra network requests, while using the "fade" animation does not.

I want to use the "slide" animation so I need to know what's going on here... !

UPDATE 2: Here's a screenshot that shows the call stack when hovering over the "Initiator" script in Chrome:

Detail

like image 437
ObiWanKenobi Avatar asked Apr 19 '13 16:04

ObiWanKenobi


1 Answers

You might also try

$(function() {
   $("#t20ContentRightWrapper").toggle("slide", { direction: "right" }, 400);
});
like image 104
aKulak Avatar answered Sep 21 '22 12:09

aKulak