Search code examples
javascriptjqueryhtmljstorage

Local storage does not clean properly on mobile browser


This will make me crazy. This happens on iphone 4S Safari(IOS 6) but not on any desktop browser.

Everytime before I make a new request I flush the jStorage, on Alert test1 everything is null as I expect. But the second alert Test2 shows an older data from storage but not the "data" received and setted in success function.

How is this possible?

$.ajaxSetup({ cache: false });
$.jStorage.flush();
    localStorage.clear();
alert("Test1 "+$.jStorage.get('token')+"tu:"+$.jStorage.get('user'));

$.ajax
    ({
        type: "POST",
        url: "rs/user/token",
        async: false,
        cache: false,
        beforeSend: function (xhr){

        },
        success: function (data){
            $.jStorage.set('token', data);
            $.jStorage.set('user',username);             
            changemenu('menu.html');
            alert("Test2 "+$.jStorage.get('token')+"tu:"+$.jStorage.get('user'));
        },
        error: function() {

        }
    });

Solution

  • Turns out it has nothing todo with localstorage, STUPID IOS 6 safari caches all POST requests, so it secretly returns same token on every request..this is the dumbest thing I've seen for long time!

    http://arstechnica.com/apple/2012/09/developers-claim-safari-in-ios-6-breaks-web-apps-with-aggressive-caching/

    Is Safari on iOS 6 caching $.ajax results?