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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:17:36+00:00 2026-05-20T07:17:36+00:00

I am building a mobile website that uses the main jquery library and some

  • 0

I am building a mobile website that uses the main jquery library and some js of our own. Our website is too big and has too much data to be a simple offline/online web app. We need web connectivity.

I’m trying to improve caching performance for caching a large amount of javascript for a mobile site. It is well known that that caching on the iPhone’s safari is limited to files 15-25kb in size, and our minified js is around 125kb.

I’ve thought about using the cache manifest, but this has the disadvantage that the browser requests the cache-manifest with each page load, and since we aren’t using a single page web app, this adds additional requests to the server.

Can we cache the javascript in localStorage (available in mobile safari and on the android browser) and then execute it from there?

  • 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-20T07:17:36+00:00Added an answer on May 20, 2026 at 7:17 am

    Yes, you can. (sorry for answering my own question, I thought this was an interesting solution)

    I found an outline of a code example here on slide #12.

    http://www.slideshare.net/jedisct1/abusing-javascript-to-speedup-mobile-web-sites

    I’ve implemented this on http://m.bbref.com/ (still in beta)

    You have to use versioning of the script url to flush the cache when a new version is created, but this works for pages with localStorage and will also work when localStorage is not available. I’ve added some debugging code to the footer to show you where the js is loading from.

    I’ve split this into a script for the header and one of the footer. These appear inline.

    In the header (I’ve put it here as we use modernizr to add some classes to the html tag and I want those there as quickly as possible for rendering purposes. Could be moved to footer.

    <script type="text/javascript">
    // .001 is the current js version
    // this script assumes it is in the root web directory.
    var js_file = "site_lib.001.js";
    // vars to store where the file is loaded from.
    var _mob_load_js = false;
    var _mob_ajax_load_js = false;
    {
        // if we have localStorage and the files exists there get it.
        if(window.localStorage && window.localStorage[js_file]) {
                // eval the js file.
                try{
                    window.eval(window.localStorage[js_file]);
    
                    // successfully eval'ed the code, so 
                    // we don't need to download it later.
                _mob_load_js = true;
                } catch (e) { _mob_load_js = false; }
        }
        else if (window.localStorage) {
            // We have localStorage, but no cached file, so we 
            // load the file via ajax, eval it and then store 
            // the file in localStorage
    
            // To remove previous versions, I remove all of our localStorage,
            // This is extreme if we store other vars there.
            window.localStorage.clear();
            // standard ajax request.
            var xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function() {
            if (xhr.readyState == 4) {
                // eval the js
                try {
                    window.eval(xhr.responseText);
                    // successfully eval'ed the code, so 
                    // we don't need to download it later.
                _mob_ajax_load_js = true;
                } catch (e) { _mob_ajax_load_js = false; }
    
            try {
                    // store the js.
                window.localStorage[js_file] = xhr.responseText;
            } catch (e) {}
            }
            else {
            return;   
            }
        };
        xhr.open("GET",js_file,true);
        xhr.send();
        }
    };
    </script>
    

    and in the footer (for performance reasons). I place the standard loading method. Note that the browsers that use this branch all cache properly so long as you have expires headers set.

    <div id="sr_external_script"></div>
    <script type="text/javascript">   
    // We haven't loaded the js yet, so we create a script 
    // tag and get the script the old fashioned way
    if (!_mob_load_js && !_mob_ajax_load_js) {
        var script=document.createElement("script");
        script.type="text/javascript";
        script.src=js_file;
        document.getElementById("sr_external_script").appendChild(script);
        // add a note to the footer
        document.write('<div>loaded from server and not stored</div>');
    }
    else if (!_mob_load_js) {
        // add a note to the footer
        document.write('<div>loaded via ajax and stored in localStorage</div>');
    }
    else {
        // add a note to the footer
        document.write('<div>loaded from localStorage</div>');
    }
    </script>
    

    I’ve confirmed in chrome and safari that the js is loaded from localStorage and the site functionality works as expected, and there is no request made to the server. And I’ve confirmed that when running on IE or firefox it loads the script as found in the footer.

    Note: I added code to wrap the evals in try catch since I was having a problem in firefox.

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

Sidebar

Related Questions

I'm building a mobile version for a website, and i'm having some problems... The
I am building this mobile website. If you check it on your mobile browser
I'm building the mobile version of a website and I want a way to
I received the task to add a mobile-friendly version of our website. Apps for
I'm building a mobile website. I use regular html for the dropdown like below.
I'm building an analytics system for a mobile application and have had some difficulty
I'm building a Webapp that uses OpenId to authenticate users, like Stackoverlfow does. There
I am building a universal app that uses a UISplitViewController for the iPad, and
I am building a website specifically for mobile devices. There is one page in
I am currently building a website optimized for mobile devices. <meta name="viewport" content="width=device-width; initial-scale=1.0;

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.