Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Local Storage VS App Cache Offline Website Browsing

After going through multiple articles, I am still not clear on the difference between Local Storage and App Cache Manifest.

Also referred: Is AppCache = Application Cache = Web Storage's LocalStorage? (SO 10986026), Application Cache is a Douchebag (A List Apart)

My AIM is to build a website with specific pages be allowed offline to user on user demand.

Steps followed :

  • I opened a site on Chrome : http://www.spritecow.com/
    And checked AppCache : chrome://appcache-internals/
    And the site was cached.

  • I closed Chrome and reloaded it. The cache was still there. Exactly what I need for offline browsing

  • Now how is this different from local storage? Tried to find the difference but all sites answer in purpose, i.e. AppCache for templates' caching and Local Storage for content within the template.

  • Certain sites do not prefer AppCache as it reloads entire cache for a single line change. Certain sites prefer only local storage. While some go for the combo of AppCache(template) and Localstorage.

Now the doubt is :

  • Local storage stores on client machine. How does AppCache storage is different if I can still access it even browser is closed.

  • As clearing cache will clear AppCache then i'd go for only Local Storage.

  • What is the best practice to be followed for offline browsing? I am completely new to this and need a little clarity on the same


EDIT

The doubt is not answered by the link (Is AppCache = Application Cache = Web Storage's LocalStorage?) as this gives difference but not based on the purpose of Offline Browsing Practices (which is the aim for this doubt).

like image 685
zeetit Avatar asked Oct 05 '15 11:10

zeetit


People also ask

Which is better local storage or cache?

Cache could be cleared any time. Local storage is sure to stay. Local storage can still be cleared out at any point.

What is the difference between HTML5 application cache and regular HTML browser cache?

HTML5 provides application cache, which means that a web application is cached, and accessible without an internet connection. whereas HTML browsers use caching to store HTML web pages by storing a copy of visited pages and then using that copy to render when you re-visit that page.

Does HTML5 support offline storage?

Apart from new elements in HTML5, this new web technology offers us Offline Storage. There are a number types of offline storage, and in this article we will specifically discuss sessionStorage and localStorage.

Does local storage work offline?

The local storage is a type of HTML5 offline storage that allows user string data to be saved synchronously in their browser. Information is kept in name and value pairs and not available between different browsers on the same device. Local storage can be used as an alternative to cookies.

What is HTML5 application cache?

HTML5 App Cache vs. Local Storage senthil | @senthil_hi 2. Application Cache A caching mechanism that enables web-based applications run offline 4.

What is local storage in HTML5?

HTML5 Local Storage: Useful Tips 4. Browser support The local storage is a type of HTML5 offline storage that allows user string data to be saved synchronously in their browser. Information is kept in name and value pairs and not available between different browsers on the same device.

Can I create offline applications with HTML5 caching?

In this tutorial you will learn how to create offline applications with HTML5 caching feature. What is Application Cache? Typically most web-based applications will work only if you're online.

What are some tips for HTML5 offline storage?

HTML5 Local Storage: Useful Tips 1 Just like cookies, HTML5 offline storage shouldn't be used to store sensitive information (e.g., user IDs or payment information). ... 2 When downloading huge files, you may encounter an error called Out of HTML5 Offline Storage Space. ... 3 Web workers cannot use the data kept in local storage in HTML.


1 Answers

AppCache use a manifest file to define what files used by the app should be stored (You can cache files and ressources like HTML pages, JS scripts, CSS styles, images,...)

LocalStorage will store data but not pages. So every javascript object that you can stringify can be stored in the localStorage.

So AppCache and localStorage aren't the same, but they are complementary.

Example

Imagine a web calendar that you want to be available offline (note: for this example, we use here a static page and data are loaded with javascript. The same can be made from a dynamic page, but this example use static).

The appcache will store the html page and the ressources that it uses (javascripts, css, images) to render you page. As you have put in your manifest file everything to be cached for the next offline access, the pages are stored and you'll be able to display your page offline at the next visit.

But problem, your calendar is displayed but is empty. All meetings and events of the month aren't there. This is because your page is stored, but you still need network to load the meetings in your calendar. And as you're offline, you have no network...

If you want to have all your meetings available offline too, you'll have to store them in the localstorage (not in the appCache, because it's not a page, it's data accessed by JavaScript.) So you will need to change your Javascript function from this :

function initApp() {
  var data = loadDataWithAjax();
  renderPlanning(data);
}

to this

function initApp () {
  var data;
  if(offline) {
    data = loadFromLocalStorage();
  } else {
    data = loadDataWithAjax();
    storeDataInLocalStorage(data);
  }
  renderPlanning(data);
}
like image 120
ylerjen Avatar answered Sep 21 '22 18:09

ylerjen