HTML5 limits the headers you can specify using the meta tag

General discussion about computers and electronics. You can post new topics here.
Locked
Jacob
Site Admin
Posts: 49
Joined: Sun Mar 21, 2021 3:24 am

HTML5 limits the headers you can specify using the meta tag

Post by Jacob »

I noticed that the w3 validator will not let you specify just any header using the http-equiv attribute of the meta tag, at least not with HTML5. In fact there appears to be only three headers that are allowed according to w3's HTML standard. As can be see here in the HTML5 specs https://dev.w3.org/html5/spec-LC/semant ... ta-element

If you try to validate your HTML code with a different header in the meta tag it will give a validation error and it will say your HTML code is not valid.

This causes a problem with webmasters that need to specify other headers but can only do it with the HTML code. Note it is also possible to set headers using server side code.

For example to set the browser to not cache using PHP the file will begin like this:

Code: Select all

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?><!DOCTYPE html>
<html lang="en">
  <head>
(No cache code from https://www.php.net/manual/en/function.header.php)
(Note there is no space between the PHP section and the start of the HTML5 (See https://stackoverflow.com/a/14613096))

I did submit an issue with w3 about this here: https://github.com/whatwg/html/issues/7435

Jacob Persico
Jacob Persico
Owner & Webmaster
Delta Fox Design
Jacob
Site Admin
Posts: 49
Joined: Sun Mar 21, 2021 3:24 am

Re: HTML5 limits the headers you can specify using the meta tag

Post by Jacob »

Many web hosting companies use Apache web server, this is usually run on Linux or another Unix-like operating system. This may be because both Linux (and many other Unix-like operating systems) and Apache web server are both free software.

If you are using an Apache web server, headers can also be added in your .htaccess file, this file goes into the same folder that your website is in. (For example: If your homepage is index.html and that is in the folder "public_html" then the .htaccess file will go in that folder too.) An .htaccess file can also be in a sub-folder too. You may have to enable showing of hidden files to see the .htaccess file.

If specifying the header in your .htaccess file does not work, you may have to enable that feature.

See: https://httpd.apache.org/docs/current/mod/mod_headers.html

You can use this site to check what headers your webpage has: https://securityheaders.com/
Jacob Persico
Owner & Webmaster
Delta Fox Design
Jacob
Site Admin
Posts: 49
Joined: Sun Mar 21, 2021 3:24 am

Re: HTML5 limits the headers you can specify using the meta tag

Post by Jacob »

The HTML5 spec I posted before might not be the best HTML5 spec. It is a bit confusing because w3 seams to have multiple different HTML5 specs listed (see https://dev.w3.org/html5/). This one https://html.spec.whatwg.org/#is-this-html5? seems to be the best.
Jacob Persico
Owner & Webmaster
Delta Fox Design
Locked