Last active
December 18, 2015 08:29
-
-
Save fancyremarker/5754275 to your computer and use it in GitHub Desktop.
Demonstration of browsers' failure to honor HTTP caching headers on history navigation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "sinatra" | |
require "json" | |
get "/data.json" do | |
content_type :json | |
headers({ | |
"Cache-Control" => "must-revalidate, no-store, no-cache, private", | |
"Pragma" => "no-store, no-cache", | |
"Etag" => "\"#{SecureRandom.hex}\"", | |
}) | |
{ value: SecureRandom.hex }.to_json | |
end | |
get "/" do | |
content_type :html | |
<<-HTML | |
<!doctype html> | |
<html> | |
<body> | |
<h1 id="data-header"></h1> | |
<a href="/other">Go To Other</a> | |
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function() { | |
$.getJSON('/data.json', function(data, text_status, xhr) { | |
$('#data-header').html(data['value']); | |
}); | |
}); | |
$(window).unload(function(){}); | |
</script> | |
</body> | |
</html> | |
HTML | |
end | |
get "/other" do | |
content_type :html | |
<<-HTML | |
<!doctype html> | |
<html> | |
<body> | |
<h1>Welcome To Other</h1> | |
<a href="/">Go Home</a> | |
</body> | |
</html> | |
HTML | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "sinatra" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To demo:
Then open http://localhost:4567/ in a browser. Fails on: Chrome, Firefox, Safari.