cache webpage in case site is down - html

I'm trying to create a static webpage that is cached in the browser. However when I take down the website the browser gives a 404 error.
I'm using the manifest attribute in HTML like so.
<html manifest="manifest.appcache">
<head>
<title>Connection Verification</title>
</head>
<body>
<h3>Testing Connection...</h3>
</body>
my manifest.appcache looks like this.
CACHE MANIFEST
#Nothing to load here
I assume the top level HTML file is implied.
I am also sending the cache-control header in the response.
cache-control: public max-age:3153600
However when I bring down the webserver and reload the page it still gives a 404 error. Is there some way to force browser to cache?

Related

Is there a way to tell Google Chrome to cache a js file?

I'm having trouble telling Chrome to cache my static resources.
I did some testing on localhost IIS with a few files:
test1.html and test2.html that have links pointing to each other, and both include the same <head> section that loads the same test.js file by script src and then by fetch().
<html>
<head>
<title>test</title>
<script src="/static/js/test.js"></script>
<script>fetch('/static/js/test.js')</script>
</head>
<body>
test123
test2.html
</body>
</html>
Response header has this: cache-control: max-age=604800
While keeping the "Disable Cache" unchecked in browser dev tool, and do a few clicks on the links between test1.html and test2.html, I can see that Firefox always uses cache whenever possible:
But Chrome seems to just occasionally use cache:
Is this behaviour controllable with any additional Chrome-specific headers?

Content Security Policy sandbox to allow redirect with META

In my web app i allow users to download html files they uploaded.
I want to make this download to be maximum secure.
If users just open a html in new tab, it is insecure, there can be some script to catch cookies or so.
I added the header "Content-Security-Policy: sandbox" for such downloads. And it solves the problem.
But i got the problem with some subgroup of html files, which are "bookmarks". Files contain simple html like
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Opening http://example.com</title>
<meta http-equiv="REFRESH" content="0;url=http://example.com">
</HEAD>
<BODY style="font-family:Tahoma;Arial;font-size:12px;padding:20px;color:#aaa">
Opening <b>http://example.com</b>...
</BODY>
</HTML>
After it is opened in new tab, i need a user to be redirected to the host in the file.
It works without the header "Content-Security-Policy: sandbox" , but doen't work with it.
I tried different sandbox modes
Content-Security-Policy: sandbox allow-scripts
Content-Security-Policy: sandbox allow-top-navigation
But nothing allows to execute that redirect.
is there a way to do it?

Cache manifest not working in safari using cross-domain refs and SSL

I have been trying to get my HTML5 offline cache manifest to work nicely in Safari when accessing the site with HTTPS.
I have the following setup:
index.html:
<!doctype html>
<html lang="en" dir="ltr" manifest="app.appcache">
<head>
<base href="https://www.example.com">
<link rel="stylesheet" href="//some.cdn.com/styles.css" charset="utf-8">
<script src="//some.cdn.com/app.js"></script>
</head>
<body>
</body>
</html>
app.appcache
CACHE MANIFEST
//some.cdn.com/styles.css
//some.cdn.com/app.js
NETWORK:
*
Accessing my site over HTTP works fine! Assets get loaded correctly and cached; I can use my app offline
Accessing my site over HTTPS in Chrome works fine as well
Accessing my site over HTTPS in Safari breaks :-( Assets get loaded normally, but won't cache. Debugging didn't got me any further. No useful information in the logs
According to the specs, referring to another domain in the cache manifest is allowed.
I have also tried using http:// or https:// explicitly in my HTML and manifest instead of the //-notation. Of no avail.
In my search online I've found some comments about cross-domain requests and that it isn't allowed in the cache manifest, but according to the W3C specs this is allowed (and proved by the fact that the browsers I tested it cache all the assets correctly, except for the combination https & safari.
So apparently I missed an important restriction of the appcache.
As mentioned in https://www.w3.org/TR/2011/WD-html5-20110525/offline.html:
If the manifest's is https: or another scheme intended for encrypted data transfer, then all URLs in explicit sections must have the same origin as the manifest itself.

What HTTP status code should I use when serving a temporary page to the browser?

When the client submit something to the server, server confirms but cannot return the result immediately, and serve a page like
<html>
<head>
<meta http-equiv='refresh' content='5; url=/somewhere/else' />
</head>
<body>
Your message is accepted, and the page will back to the home after 5 seconds.
But the browser will put that temporary page in the history. My question is what HTTP status code may I use in this situation to tell the browser not record the URL?
Status code should be 200. If you do not want browser to cache, you should set Cache related meta fields.

HTML5 offline data storage

Im using HTML5 offline storage
My Index.html page
<!DOCTYPE html>
<html lang="en" manifest="/offline-cache.manifest">
<head>
<meta charset="utf-8">
<title>HTML5 offline code demo</title>
</head>
<body>
<div id="content">
<img src="http://increaserss.com/wp-content/uploads/flickr-rss.jpg" alt="img to be cached" />
</div>
</body>
</html>
offline-cache.manifest file
CACHE MANIFEST
#just want to cache that remote image only
http://increaserss.com/wp-content/uploads/flickr-rss.jpg
My htaccess
RewriteEngine On
AddType text/cache-manifest .manifest
After loading the page for the first time with internet and then disabled the internet and trying to access this index.html ,caching works fine but again if i hit f5 the image is not shown (only alt text is there) and when i click on the url bar and hit enter (as if were a new request) it is working fine...any way to sustain cache for a page refresh(f5) ?
I would first validate if you can pull assets that are not on your server and then cache them? I am thinking you might be blurring the lines between browser caching and HTML 5 application caching?
I would also make sure you are not using Internet Explorer as it doesn't support offline Caching.
The Cache manifest should also include a version # after the CACHE MANIFEST header (ex. # version 1.4) and the cached files should be under the CACHE: header. For example.
CACHE MANIFEST
# version 1.4
CACHE:
images/flickr-rss.jpg
Please let us know how you made out.
You are using a full URL, is the image not on the same server? If so, that could prevent it from getting cached. If you're using Chrome it reports the cache events to the console.