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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With