Reputation: 61
In HttpServletResponse
, invocation of setHeader()
method is the same as we set value in html <head>
tag?
Java Code:
response.setHeader("Pragma", "no-cache");
response.setIntHeader("Expires", -1);
Html:
<HTML><HEAD>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
</HEAD><BODY>
</BODY>
</HTML>
Are both of them the same?
Upvotes: 6
Views: 5772
Reputation: 76709
No.
Unlike META tags in HTML documents, HTTP response headers set by the HttpServletResponse methods can be interpreted and acted upon by any of the nodes in the network, that exist between the client and the server. Typically these are proxies, which do not bother with the content of the HTML documents. The reason such elements can act on these headers, is that the HTTP response headers apply not only to the client(browser) but also to any of the intermediaries; the HTTP specification allows for interpretation of headers by intermediaries.
If you want all elements in a network to obey the cache headers, which you are intending to set (in the HTML document), then specify the HTTP response headers (using the HttpServletResponse object). All intermediaries are expected to obey these headers.
Only browsers tend to act on the META tags, for only they parse the HTML document; in other words, the META tags will determine the expiry settings of a document for the browser local cache, and not of the proxy caches.
Related resources
Upvotes: 5
Reputation: 89169
No,
HTTP headers are RFC 2616 headers, so when client gets response from the server, it translate these HTTP response headers first.
HTML data are just enity body in the HTTP message, and only the releavant interpreter (e.g. browser) can translate it.
Upvotes: 1