Last active
September 19, 2018 08:24
-
-
Save bolasblack/737d7e36aada2e950c36ed88304597f7 to your computer and use it in GitHub Desktop.
how to prevent bfcache
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
// modified from https://mixmax.com/blog/chrome-back-button-cache-no-store | |
/** | |
* Run this by downloading this script to your computer, then: | |
* 1. $ npm install express | |
* 2. $ node thisscript.js | |
* 3. Open localhost:8030/nocache and then localhost:8030/nostore | |
*/ | |
const app = require('express')() | |
app.get('/nocache', function(req, res) { | |
res.setHeader('Cache-Control', 'no-cache') | |
res.send(` | |
${new Date().toString()}<br /> | |
<div id="api"></div><br /> | |
<script>fetch(location.pathname + '/api').then(r => r.text()).then(r => document.getElementById('api').textContent = r)</script> | |
<a href="https://mixmax.com">Click to navigate away and then press Back. It will show the same timestamp.</a> | |
`) | |
}) | |
app.get('/nocache/api', function(req, res) { | |
res.setHeader('Cache-Control', 'no-cache') | |
res.send(new Date().toString()) | |
}) | |
app.get('/nostore', function(req, res) { | |
res.setHeader('Cache-Control', 'no-cache, no-store') | |
res.send(` | |
${new Date().toString()}<br /> | |
<div id="api"></div><br /> | |
<script>fetch(location.pathname + '/api').then(r => r.text()).then(r => document.getElementById('api').textContent = r)</script> | |
<a href="https://mixmax.com">Click to navigate away and then press Back. It will show the same timestamp.</a> | |
`) | |
}) | |
app.get('/nostore/api', function(req, res) { | |
res.setHeader('Cache-Control', 'no-cache, no-store') | |
res.send(new Date().toString()) | |
}) | |
app.listen('8030') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment