Omit current page from HTML5 offline appcache but use cached resources
Asked Answered
S

3

7

For performance purposes, I want to have some of my web pages use resources that have been cached for offline use (images, CSS, etc.) but to not have the page itself cached as the content will be generated dynamically.

One way to do this would be to refactor my pages so that they load the dynamic content via AJAX or by looking things up in LocalStorage. Details may vary, but broadly speaking, something like that.

If it's possible, I'd prefer to find a way to simply instruct the browser to use cached resources (again, images, CSS, etc.) for the page but to not actually cache the (dynamically generated) HTML content itself.

Is there a way to do that with HTML5 offline appcache? I'm under the impression that the answer is "no" because:

  • Any page that includes the manifest will be cached so I can't specify the cached resources in the page itself.
  • There is no way to tell a previous page "use offline assets for this other page but don't actually cache the HTML on that page". You have to specify the page itself, which means the HTML will be cached.

Am I wrong about that? It seems like there is probably some tricky (or not-so-tricky) way around that. Now that I've typed it out, I wonder if including the page explicitly in the NETWORK section of the appcache manifest will do the trick.

Sampan answered 30/11, 2011 at 1:36 Comment(0)
E
7

My answer is "yes".

I have worked on a web-app where I listed all the necessary resources in the manifest, and set the NETWORK section to *.

The manifest is then included only on the main landing page. So all resources are cached the first time you visit the site and and it works a treat.

In short,

  • one of your pages must include the manifest and will therefore be cached.

    maybe you can have the manifest loaded in a iframe and not have the whole page cached, just a thought.

  • list all your resources to be cached in the CACHE section

  • set the NETWORK section to *
Erinerina answered 30/11, 2011 at 2:0 Comment(6)
Oh crud, it actually just works like that out of the box with the typical use case scenario that I was already employing. Now don't I feel foolish for not testing that first!Sampan
are you sure that this way the non cached-page uses the cached resources? I'm not so sure. this works, but I think the page will load the resources from the server ...Abroms
@pkyeck the application will use the cached resources whenever available. To get the latest content you will have to either modify the manifest or clear the cache. A neat technique is to MD5 sum your manifest and write the value in manifest file so when my manifest changes the MD5 value changes which gets written to the file triggering a cache update. This is done server-side btw.Erinerina
any example you can show/link to? because my dummy implementation of a page w/o manifest embedding an iframe with manifest attached uses the "normal" resources from the server ...Abroms
@pkyeck See the top answers in this question. stackoverflow.com/questions/7843531/… Have a look at the js source for iframes in the timer-tab link. It is minified but hopefully you can follow it :D If that doesn't help then link me to your dummy implErinerina
but on the timer-tab example, the main/root page is also cached. this is why it can access the applicationCache. but I (and Trott asking the original Q) want to use the appCache on the main page w/o adding it to the cache itself because it's highly dynamic and changes every few minutes. i'll put together a dummy I can post a link to ...Abroms
A
2

I'm fairly certain that the answer to this is no. If you use the Network section in Chrome, then it shows which resources are loaded from the cache and which are loaded from the server. I have attempted to set the appcache as described above and the resources are always loaded from the server. Would I be correct in assuming that if the current page is not in the appcache then it wont bother to check in the appcache for any of the resources?

Azrael answered 4/7, 2013 at 14:34 Comment(0)
I
0

What I've found that is working is to list those files that you don't want cached in appcache in the NETWORK: section of the manifest. For me, that meant adding *.asp* to the network section. Now, none of the classic asp files, or aspx files are cached.

Indigested answered 14/1, 2014 at 16:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.