How to set an expiration date for an html link

I'm not sure if I'm being a complete noob at this (it's been a looooong night :D), but is it possible to cache links with .htaccess? I know that you can set extensions and stuff like jpg, png, css, js, etc.

And if you've ever hosted a website, I'm sure you've probably used one of those online "website optimizers", and I keep getting the message "The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:" ...followed by a list of outside links like Facebook and Google.

Any ideas?


You cannot alter the headers or the content for external resources like Google cdn or facebook. Assume that big companies like Google and Facebook know how to cache and what resources are viable to cache and for how long.

For resources on your own server, you can set the Cache-Control header with a custom time to tell the client for how long the page can be cached.

<FilesMatch .(css|js)$>
   Header set Cache-Control "public, no-transform, max-age=600"
</FilesMatch>

You can check how long it takes to load certain resources on your page by going to your browser and opening the developer console. Under the network tab you can see all requests that are being made. Make sure to load the page both with cache and without cache.

链接地址: http://www.djcxy.com/p/20302.html

上一篇: AWS CloudFront利用浏览器缓存

下一篇: 如何设置html链接的到期日期