How do you cache javascript on iphone Safari using html5 localStorage?
By : user2771925
Date : March 29 2020, 07:55 AM
I hope this helps . 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. code :
<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>
<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>
|
Is there a way to persist cookies or HTML5 localStorage across WebBrowser instances on Windows Phone?
By : Andres Bravo Sandova
Date : March 29 2020, 07:55 AM
Does that help I'm not sure if this is expected behaviour or not. To get at the Isolated Storage you will need to use JS/.NET interop.
|
html5 localstorage error safari
By : user3483740
Date : March 29 2020, 07:55 AM
seems to work fine What the issue is The localStorage size is limited to a relatively small size (a few MB tops). In Safari this exception occurs in two cases:
|
Better design for data stored using HTML5 localStorage
By : Buddy Palumbo
Date : March 29 2020, 07:55 AM
should help you out Not exactly sure what you are looking for. Generally I use localStorage just to store stringified versions of objects that fit my application. Rather than setting up all sorts of different keys for each variable within localStore, I just dump stringified versions of my object into one key in localStorage. That way the data is the same structure whether it comes from server as JSON or I pull it from local. You can quickly save or retrieve deeply nested objects/arrays using JSON.stringify( object) and JSON.parse( 'string from store');
|
Does HTML5 localStorage persist across browser instances?
By : Todor Hristov
Date : March 29 2020, 07:55 AM
this will help Local Storage is persistant in different tabs/windows when application is opened from same domain. 5MB storage per Domain is provided. LocalStrorage can be wiped only when u remove it manualy by LocalStorage.clear(); For more on info on html5 local storage please visit : LOCALSTORAGE in html5
|