what is style.css?ver=1 tag?

前端 未结 6 1988
温柔的废话
温柔的废话 2020-12-15 06:26

I found out that some websites use css tag like style.css?ver=1. What is this?

What is purpose of ?ver=1?

How do I do it in code?

6条回答
  •  [愿得一人]
    2020-12-15 06:43

    Adding '?ver=1' makes the HTTP request look like a GET query with parameters, and well-behaved browsers (and proxies) will refuse to cache parameterized queries. Of course well-behaved browsers (and proxies) should also pay attention to the 'Cache-control: no-cache', 'Expires', 'Last-Modified', and 'ETag' response headers (all of which were added to HTTP to specify correct caching behavior).

    The '?ver=1' method is an expensive way to force behavior when the site developer doesn't know how (or is too lazy) to implement the correct response headers. In particular, it means that every page request is going to force requesting that CSS file, even though, in practice, CSS files change rarely, if at all.

    My recommendation? Don't do it.

提交回复
热议问题