Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 558673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:09:24+00:00 2026-05-13T12:09:24+00:00

Using jquery.load() to replace the content of a div everything works great, however there

  • 0

Using jquery.load() to replace the content of a div everything works great, however there is a major performance issue. The page loaded into the div contains some external JavaScript files and using HttpWatch I have observed the following:

0   0   GET (Cache) text/javascript <host>/js/file1.js
0   0   GET (Cache) text/javascript <host>/js/file2.js
0   0   GET (Cache) text/javascript <host>/js/file3.js
...
etc.

and a little further below (during the same load()):

571 129862  GET 200 text/javascript <host>/js/file1.js?_=1263399258240
569 26439   GET 200 text/javascript <host>/js/file2.js?_=1263399258365
572 14683   GET 200 text/javascript <host>/js/file3.js?_=1263399258396
...
etc.

The same scripts seem to be loaded again for some reason. Even worse, there appears to be a freeze in the browser just before the files are fetched again.

Can I prevent jQuery from loading the files again? This whole issue is causing around a 5-sec delay to my page. Also, what is the meaning of the _=1263399258240?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:09:25+00:00Added an answer on May 13, 2026 at 12:09 pm

    jQuery has three different cache options. The default null allows caching for all requests except scripts and json requests, whilst true and false apply to all requests. As far as I can tell, you cannot provide an options argument in the load() method, so you need to change the global jQuery ajax options.

    I’ve given different ways to do this below.

    1. The first attempts to retain the previous global option after your request is complete (but does have its drawbacks).
    2. The second disregards the default setting and just sets the option so that you always allow cache to be used for ajax results (if this is not an issue for you, I’d recommend this one, as it’s the simplest, with no hidden pitfalls), and
    3. the third example is if you want to allow caching of scripts, but not other ajax requests.

    Example 1:

    My first example shows how to do this if you want to revert back to normal settings after the load() request:

        //first store defaults (we may want to revert to them)
     1: var prevCacheVal = $.ajaxSettings.cache; 
        //then tell jQuery that you want ajax to use cache if possible
     2: $.ajaxSetup({cache: true}); 
        //then call the load method with a callback function 
     3: $(myDiv).load(myURL,function(){
          /* revert back to previous settings. Note that jQuery makes 
             a distinction between false and null (null means never
             cache scripts, false means never cache anything). so it's
             important that the triple-equals operators are used, to
             check for "false" and not just "falsey" */
     4:   if (prevCacheVal === false) $.ajaxSetup({cache: false})
     5:   else if (prevCacheVal !== true) $.ajaxSetup({cache: null});
          //else prev was true, so we need not change anything
     6: });
    

    Important Note that in doing the above, you need to be careful you’re only sending one request at a time, as storing and switching the “default” each time could lead to race conditions. If you need the above functionality and ability to send parallel requests, you’d be better off writing your own wrapper for the jQuery.ajax() method so you can pass in the cache option on a per-request basis. This would be similar to Andres’ suggested approach below, but with the fixes I suggested to specify cache: true and to use jQuery.html(); rather than innerHTML. However, it gets more complicated than that, because internally, jQuery.html(); requests scripts using the global option, so you’d also need to override some of the internal functionality deep within function calls that html(); makes – not something to be done lightheartedly, but certainly possible.

    Example 2: (recommended for the original question asker)

    Now, if you don’t care about restoring defaults, and want cache to be on for all ajax requests, you can simply call $.ajaxSetup({cache: true}); and call load() as you previously did:

     $.ajaxSetup({cache: true}); 
     $(myDiv).load(myURL);
    

    Example 3:

    And if you want the myURL to not be loaded from cache (let’s say its dynamic), but do want to cache the scripts, you’ll need to add a unique-ish/random query to myURL, such as:

     $.ajaxSetup({cache: true}); 
     $(myDiv).load(myURL + "?myuniquetime=" + Date.getTime()); 
     /* getTime() is milliseconds since 1970 - should be unique enough, 
        unless you are firing of many per second, in which case you could
        use Math.random() instead. Also note that if myURL already includes
        a URL querystring, you'd want to replace '?' with '&' */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery load method to update divs , it works great until
There's placeholder on the page that is loaded asynchronously using jQuery load method. Page
This function updates my content using the .load method from JQuery. The code works
Using tinyMCE jquery version. I have a content page where there could be many
I know that Jquery.LOAD is supposed to replace all the content of a div,
I was using jQuery.load() to load a html page's content into a lightbox. The
When using jQuery.load to dynamically load HTML content into a webpage, what is the
I am trying to load mschart in my aspx page(SalesOverview.aspx) using jQuery.load() method, I
I am using jQuery to load a page by AJAX using $.ajax (suppose test.html).
We are using jquery to .load() a form into a div We then use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.