What's wrong with my appcache manifest test?
Asked Answered
D

2

19

I'm trying to test Appcache manifest:

<?php

// reference: http://diveintohtml5.info/offline.html

header( "Content-Type: text/cache-manifest" );
header( "Cache-Control: max-age=0, private, must-revalidate" );

?>CACHE MANIFEST

# todo

/cachetest/tryme/vid/missouristate

Now this appears to have the right headers in Network inspector, and is linked to at the top of a html file:

<!DOCTYPE html>
<html manifest="/cachetest/cache.manifest/index.php" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

However, there is zero evidence this is actually working. If it were working, it should not show any other items, unless it had a NETWORK * setting in that file, as described here:

Finally, let’s examine the network section. The network section in this cache manifest also has just a single line, a line that contains just a single character (*). This character has special meaning in a network section. It’s called the “online whitelist wildcard flag.” That’s a fancy way of saying that anything that isn’t in the appcache can still be downloaded from the original web address, as long as you have an internet connection. This is important for an “open-ended” offline web application. It means that, while you’re browsing this hypothetical offline-enabled Wikipedia online, your browser will fetch images and videos and other embedded resources normally, even if they are on a different domain. (This is common in large websites, even if they aren’t part of an offline web application. HTML pages are generated and served locally, while images and videos are served from a CDN on another domain.) Without this wildcard flag, our hypothetical offline-enabled Wikipedia would behave strangely when you were online — specifically, it wouldn’t load any externally-hosted images or videos!

This looks like similar web-apps that work offline, though I have to wonder if I have to set up https on localhost or local-ip to get the browser to even recognize it.

I remember seeing something recently about Appcache now requiring https as Serviceworker requires https as well. Is that something I have to set up in test environment for this to work in the latest browsers? Can I change an about:config to use on plain http? Or am I missing something else?

Discrete answered 25/10, 2015 at 6:49 Comment(3)
Downvoted why? Because MDN says it's deprecated? It is supported by browsers though.Discrete
I am not the downvoter, but I do not understand what you mean by "zero evidence this is working" or "it should not show any other items". When I tried your code I see the browser get the html, get the manifest, get the resource, then double check the manifest, as specified. applicationCache.status also says 1 instead of 0, indicating cache is functional. All without https. How do you expect it to work?Ephod
@Ephod Sorry I wasn't clear, I have included quote from the docs I was reading that should clarify that part.Discrete
J
1

You are not doing anything wrong.

Appcache does not work in Firefox. (at least for me in Firefox 42.0)

But it does work in Chrome (I tried on 46.0.2490.86 (latest)).

Some testing pages:
http://appcache-demo.s3-website-us-east-1.amazonaws.com/without-network/

http://appcache-demo.s3-website-us-east-1.amazonaws.com/with-network/

http://appcache-demo.s3-website-us-east-1.amazonaws.com/offline-iframe/

And of course you can make your own empty cache manifest file and see for yourself.

Good Luck

Source of testing pages: http://alistapart.com/article/application-cache-is-a-douchebag

Jews answered 15/11, 2015 at 16:46 Comment(3)
Really? It's supposed to work. developer.mozilla.org/en-US/docs/Web/HTML/…Discrete
Overdrive Media's offline library book reader works in Firefox, and it has <html manifest="/_d/cache.manifest"> Does the .manifest file type mean you have to set up some special htaccess or server setup to have php(for example) serve a .manifest file?Discrete
Yes, but that's just another way to write Content-Type: text/cache-manifest, I was doing that , in apache .htaccess I added AddType text/cache-manifest .appcache and I also tried AddType text/cache-manifest .manifest, but Firefox doesn't care what's in that file, it caches everything that it wants, but same setup does work in Chrome, without changing anything.Hackathorn
H
1

Check the following steps to see why your code is not working, then maybe your code will work.

  • you are using php file, but The recommended file extension for manifest files is: ".appcache"
  • if you use .appcache then don't need to set header, browser will get text/cache-manifest header for .appcache extension.
  • in manifest The first line, CACHE MANIFEST, is required. so remove php code from first.
  • CACHE MANIFEST section only get resource like JS, CSS, images etc.. I think the name of the page you entered is incorrect.

And after checking the steps above, the manifest will probably be ready as follows.

name will be : index.appcache

CACHE MANIFEST
# todo
/cachetest/images/1.jpg
/cachetest/css/style.css

NETWORK:
/login.php

FALLBACK:
/html/ /cachetest/offline.html
<!DOCTYPE html>
<html manifest="/cachetest/cache.manifest/index.appcache" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>

The names of the list of files are given for example.

Hemihedral answered 16/5, 2020 at 17:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.