- 🔭 I'm currently working on the crm web and low code in YMM.
- 🌱 I’m currently learning Node/Python/UE(user experience).
You can also read my articles in blog
在实践中学习,不要模棱两可
You can also read my articles in blog
var express = require('express')
var path = require('path')
// 此模块是 express 的依赖项
var serveStatic = require('serve-static')
var logger = require('morgan');
var app = express()
app.use(logger('dev'));
app.use(serveStatic(path.join(__dirname, 'public'), {
maxAge: 360 * 1000,
setHeaders: setCustomCacheControl
}))
function setCustomCacheControl (res, path) {
if (serveStatic.mime.lookup(path) === 'text/html') {
// Custom Cache-Control for HTML files
res.setHeader('Cache-Control', 'public, max-age=360000')
}
}
module.exports = app
场景:在此项目中,直接请求:http://localhost:3000/stylesheets/style.css
发现:
即使对 style.css
设置了 Cache-Control: public, max-age=360
F5 刷新页面发现,虽然是强缓存(Expire 或 Cache-Control
),但状态码是 304,而非200,发现走了协商缓存(Etag
)
有点茫然了,搜了下,有些资料可以参考:
Chrome appears to be ignoring your Cache-Control settings if you're reloading in the same tab:https://stackoverflow.com/questions/11245767/is-chrome-ignoring-cache-control-max-age
Cache-Control
html demo
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Test Page</title>
</head>
<body>
<p>
<a href="self.html">Link to the same page.</a>
If correctly cached, a request should not be made
when clicking the link.
</p>
</body>
</html>
Cache-Control: public, max-age=360
,刷新页面,发现 HTML 的状态码是 304,走了协商缓存,而 CSS 却是 200 from memory cache
,走了强缓存。强制刷新(200*2) -> F5(cmd+r) 刷新(304+200) -> F5(cmd+r) 刷新(304+200)
新开一个 Tab,贴上 CSS 的URL ,Enter ,发现是 200 from memory cache
,走了强缓存。
刷新该 CSS 资源的 URL,发现是 304
,走了协商。刷新同一个 Tab,Chrome 会对当前 URL 代表的资源忽略 Cache-Control
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.