简体   繁体   English

网页中使用的外部JS文件的控制到期

[英]Control expiry of an external JS file used in a web page

In order to cause the javascript file to expire on a web page perhaps someone could answer any of the following specific questions: 为了使javascript文件在网页上过期,也许有人可以回答以下任何特定问题:

  1. Does the script file expire when the page expires? 页面过期时脚本文件会过期吗?
  2. Should I add a version number to the name of my various script files (and html pages?) 是否应该在各种脚本文件(和html页面)的名称中添加版本号?
  3. If there is no attribute for expiry, is there server side header info that can be added to the script? 如果没有到期属性,是否可以将服务器端标头信息添加到脚本中?
  4. Is there a recommended best practice(s) where this is concerned? 是否有建议的最佳实践来解决?

1) Does the script file expire when the page expires? 1)页面过期时脚本文件是否过期?

No, it expires according to the caching information provided when the js file was served up, unless it is an html application in which case it can be expired earlier by changing the timestamp on the manifest file. 不可以,它会根据提供js文件时提供的缓存信息而过期,除非它是html应用程序,在这种情况下,可以通过更改清单文件上的时间戳记使其更早过期。

2) Should I add a version number to the name of my various script files (and html pages?) 2)我应该在各个脚本文件(和html页面)的名称中添加版本号吗?

This is a common practice for static content in combination with a very long expiry time 这是静态内容的常规做法, 同时需要很长的到期时间

3) If there is no attribute for expiry, is there server side header info that can be added to the script? 3)如果没有到期属性,是否可以将服务器端标头信息添加到脚本中?

No (you can embed meta header data in HTML but not in other content types). 否(您可以将元头数据嵌入HTML中,但不能嵌入其他内容类型中)。

4) Is there a recommended best practice(s) where this is concerned? 4)是否有建议的最佳实践来解决?

Yes, there's lots of "best practices". 是的,有很多“最佳做法”。 Usually option 2 with the added caveat that the version information should be in the path rather than the query. 通常,选项2带有附加的警告,即版本信息应位于路径而不是查询中。 Doing this by hand can be a PITA: mod_pagespeed (and some other tools) do it automagically. 手动执行此操作可以是PITA:mod_pagespeed(和其他一些工具)可以自动执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM