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 6943011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:06:01+00:00 2026-05-27T13:06:01+00:00

New to JQuery but want to use it to prefetch html pages in the

  • 0

New to JQuery but want to use it to prefetch html pages in the background (about four @ about 4kb each) but I am not quite sure I am doing this right.

Here is the code I have come up with:

$(document).ready(function() {
    var my_url;
    $('[rel=prefetch][href$=.html]')
        .each(function() {
            my_url = $(this).attr('href')
            $.ajax({
                url: my_url, 
                dataType: 'text',
                headers:{'X-Moz': 'prefetch'} 
            });
        });
});

Basically, I have some links with ‘rel=prefetch’ in the head of the document and the code snippet above is inserted when the browser is not Firefox. My application renders things differently when the ‘X-Moz: prefetch’ header is detected so this is sent here as it is needed.

The code is supposed to just get the html and cache without processing scripts which I believe ‘dataType: text’ should take care of.

Will appreciate some eyes on this and suggestions. Queries are:

  1. Is the code above valid? If not what is the fix?
  2. What do I need to change to limit the selector’s scope to the < head > … < /head > section?
  • 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-27T13:06:01+00:00Added an answer on May 27, 2026 at 1:06 pm

    Got it working. The issue was because the jquery snippet was not running when I linked to JQuery using the google api. When I serve it directly from my site, in which case all the js is combined into one file, it works.

    I noticed this when I used the developer tool in Safari.

    The full code is:

    (function ($) {
        $(document).ready(function() {
                var this_browser, my_url;
                // Prefetch pages for non Firefox browsers
                this_browser = new Browser();
    
                if ( this_browser.getBrowserName() != this_browser.BROWSER_FIREFOX ) {
                    // Asynchronously prefetch html as text strings
                    // I.E., do not process scripts in incoming html
                    // See: http://ernstdehaan.blogspot.com/2009/08/prefetching-files-using-jquery.html
                    $('link[rel="prefetch"][href$=".html"]')
                        .each(function() {
                            my_url = $(this).attr('href');
                            $.ajax({
                                url: my_url, 
                                dataType: 'text',
                                headers: {'X-Moz': 'prefetch'} 
                            });
                        });
                }
        });
    }(jQuery));
    

    Safari alerted me that the “(jQuery)” bit was generating an error.

    It turned out that this was because the code was fired before JQuery was loaded.

    Also forgot to mention that

    $('head link[rel="prefetch"][href$=".html"]')
    

    Limits the selector.

    I have also removed the browser detection and just use this for all browsers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to jQuery but want to use this form validation plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/ In
I am new in Jquery. I want to use sortableUI to my datalist. Each
I am new jquery mobile. i want to use showPageLoadingMsg() of jquery mobile.But it
I am familier with jQuery,Ajax and JSP Servlets but new to Struts2.I want to
I've been trying to use the new jquery-ui, and all but the resizable function
I know this question is quite basic but I am new to JQuery and
Ok, so I'm quite new to jQuery, but found this bizzare problem just now,
I am new to Jquery.. I want use bounce effect in my application..I have
I am new to jQuery . I know the use of jQuery but I
I'm new to JQuery and so far I'm using prototype. But now I want

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.