Sobes.tech
Junior

How to specify an HTTP header using a meta tag?

sobes.tech AI

Answer from AI

Using the http-equiv attribute in the <meta> element allows duplicating the action of HTTP headers.

Example of specifying content type:

<!-- Duplicates the HTTP header Content-Type -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Example of specifying cache control directive:

<!-- Duplicates the HTTP header Cache-Control -->
<meta http-equiv="Cache-Control" content="no-cache">

Example of setting page refresh interval:

<!-- Duplicates the HTTP header Refresh -->
<meta http-equiv="Refresh" content="5; url=https://example.com/">

List of commonly used http-equiv values:

Value Corresponding HTTP header Purpose
Content-Type Content-Type Indicates the MIME type of the document and encoding.
Default-Style Default-Style Specifies the default style (CSS) to be applied.
Refresh Refresh Specifies the interval for refreshing or redirecting the page.
Set-Cookie Set-Cookie Sets a cookie for the current document.
X-UA-Compatible X-UA-Compatible Provides instructions for rendering modes in older versions of Internet Explorer.
Content-Security-Policy Content-Security-Policy Defines content security policy to prevent XSS attacks.

It is important to note that meta tags with http-equiv are processed by the browser and are not a full replacement for HTTP headers sent by the server. Some headers, critical for security or performance (e.g., Strict-Transport-Security), cannot be set via meta tags.