What are http-equiv="Pragma" and http-equiv="Cache-Control" goals for?

Asked

Viewed 1,584 times

2

I am using the W3C validator in an old project and it identified some errors in the following goals:

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="Cache-Control" content="no-cache, no-store">
<meta http-equiv="Pragma" content="no-cache, no-store">

What is their actual functionality? They are still used?

  • About the X-UA-Compatible the answer is here: https://answall.com/questions/209593/qual-%C3%A9-a-fun%C3%A7%C3%A3o-da-meta-tag-x-ua-compatible-dentro-do-html/209599#209599

  • but guys, I’m not asking about X-UA-compatible...

  • @Netinhosantos , in addition to X-UA, as mentioned above, there are still two other tags that are not mentioned in the other answer... I don’t understand your Duplicate vote

  • is written in the title of the question.

2 answers

5

Every time we see pragma in technical things it means that there will be something that is dependent on implementation, ie, each implementor of the specified technology can use that as you want and put what you want. In HTML the most common is to find as a cache control compatibility mode for version before HTTP 1.1. This can be seen on MDN. In practice you will hardly have problems if you don’t use it, or if you have other more serious ones for the use that everyone does today.

Precisely the Cache-Control is used since 1.1 and as the name already says provides specific directives to control the cache of that page:

Cache-Control: max-age=<seconds>
Cache-Control: max-stale[=<seconds>]
Cache-Control: min-fresh=<seconds>
Cache-Control: no-cache 
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: only-if-cached
Cache-Control: must-revalidate
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: public
Cache-Control: private
Cache-Control: proxy-revalidate
Cache-Control: max-age=<seconds>
Cache-Control: s-maxage=<seconds>
Cache-Control: immutable 
Cache-Control: stale-while-revalidate=<seconds>
Cache-Control: stale-if-error=<seconds>

3


About Error

The mistake is because these values for the meta http-equiv are obsolete. Therefore they are not valid.

inserir a descrição da imagem aqui

See here which attributes are valid according to the current documentation of W3C https://www.w3.org/TR/html/document-metadata.html#element-attrdef-meta-http-equiv

inserir a descrição da imagem aqui

Source: https://www.w3.org/TR/html/document-metadata.html#pragma-Directives

About what is the Cache-Control: https://developer.mozilla.org/pt-PT/docs/Utilizando_meta_tags#Cache-Control

The directive "cache-control:no-cache" has the same function as "pragma:no-cache". The ideal way to use this instruction is to use both forms if you do not know whether or not the server is HTTP 1.1 compliant.

About the Pragma_no-cache: https://developer.mozilla.org/pt-PT/docs/Utilizando_meta_tags#Pragma_no-cache

Makes the browser not cache the page. Differs from "cache-control:no-cache" because it is recognized by all versions of HTTP.


About HTTP Cache I recommend this article from Google https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching

"The recovery of something by the net is slow and expensive. Large responses require multiple back and forth between the client and the server, which slows down their availability and processing by the browser, as well as generating data costs for the visitor. As a result, the ability to cache and reuse previously recovered resources is a critical aspect of performance optimization.

The good news is that every browser is provided with an implementation of an HTTP cache. All you have to do is ensure that each server response provides the correct HTTP header directives to instruct the browser on when and for how long it can cache the response."

inserir a descrição da imagem aqui

Continues here: https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching

  • One question I doubt is that the directive is divided into requests and answers, must-revalidate for example, it is used in responses, in turn max-agein the requests, so they can combine, I did not understand the question of when to use what in that situation, kkkk

  • @Magichat I also wouldn’t know how to tell you with technical precision about these things, just by doing research, but these attributes you mentioned are in Maniero’s answer, sometimes he knows how to answer you...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.