Mark Kramer
Mark Kramer

Reputation: 3214

HTML cache version

You know how if you use

<script type="text/javascript" src="urlhere.js?version=1.0.0"></script>

the browser caches the javascript file and updates it when you give it a new version?

Is there a way to do that with the HTML code?

Because I want the browser to cache the HTML, but then update when the code is changed.

Is that possible?

Upvotes: 1

Views: 1644

Answers (1)

Brad Christie
Brad Christie

Reputation: 101604

The best way to handle caching would be at the server level, specifying two tags:

  • Expires
    When the date specified has past, it tells the browser the content is no longer valid and it must be refreshed.
  • Cache-Control
    Without involving the date, it lets the browser know how it should handling caching for the page.

Note: The browser should already take care of this as it (in the background) already looks at the last modified date of the file. However, the above methods are valid ways of overriding (extending) this kind of detection in places where the last modified date may not necessarily reflect change.

Upvotes: 1

Related Questions