質問

This is question logically follows this question:

Is HTML5 application caching relevant?

It is obvious that popular sites are not using HTML 5 application caching to save static resources as it was designed for.

Just check for the manifest attribute in the <html> tag. It is not there.

Looking into it further HTML5 localStorage is not being used either.

As a test case I looked at

  • www.google.com
  • www.twitter.com
  • www.facebook.com

Just go into the console and type

localStorage.

and the console should pop up a list of keys.

None of these sites saves their static data to the disk?

Why is this?

It seems like a waste of resources to hit the network for a resource that has not changed.

To elaborate. If you click reload, the page will re-download static resources. With Google you can even see the word static used in the URL path. However for this question I use the conceptual meaning of the word.

役に立ちましたか?

解決

It is obvious that popular sites are not using HTML 5 application caching to save static resources as it was designed for.

You’ve misunderstood what application caching was designed for. Here’s the first paragraph of the application cache spec:

In order to enable users to continue interacting with Web applications and documents even when their network connection is unavailable — for instance, because they are traveling outside of their ISP's coverage area — authors can provide a manifest which lists the files that are needed for the Web application to work offline and which causes the user's browser to keep a copy of the files for use offline.

http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#introduction-5

So, application caching was designed to allow web app authors to make their apps work when a network connection isn’t available.

I can’t envisage how Google, Twitter or Facebook could usefully work without a network connection. They all rely on the user interacting with enormous amounts of data (in Twitter and Facebook’s case, data about other users) on their servers. They’re inherently useless without a network connection.

Likewise, localStorage isn’t designed for storing page resources that may change. (I presume you’re suggesting that these sites could store CSS, JavaScript and image files in localStorage — apologies if I’ve misunderstood.)

This specification introduces two related mechanisms, similar to HTTP session cookies, for storing structured data on the client side...

The first is designed for scenarios where the user is carrying out a single transaction, but could be carrying out multiple transactions in different windows at the same time...

The second storage mechanism is designed for storage that spans multiple windows, and lasts beyond the current session. In particular, Web applications may wish to store megabytes of user data, such as entire user-authored documents or a user's mailbox, on the client side for performance reasons...

http://www.w3.org/TR/webstorage/#introduction

In order to use localStorage for CSS, JavaScript and image files, you’d need some JavaScript in the page that checked localStorage for each resource required by the page, then (somehow) checked the server to see if there was a newer version, grabbing it if necessary, then added the resource to the DOM of the page (and stored it in localSorage if it was new).

That’s a lot of code to basically replicate the caching that web browsers already do. And while your JavaScript is checking localStorage and the server, the page stops rendering. Whereas when the browser downloads CSS and image files itself, the page can carry on rendering whilst it does so.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top