Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 3.15 KB

File metadata and controls

41 lines (33 loc) · 3.15 KB

5. If It Can Be Done Using an HTTP Header, Use an HTTP Header

<meta http-equiv="Last-Modified" content="Monday, 07 October, 2019 02:21:47AM">
<meta name="Last-Modified" content="Monday, 07 October, 2019 02:21:47AM">
<meta name="Last-Modified-Date" content="Mon, Oct 07, 2019">
<meta name="Last-Modified-Time" content="02.21AM IST">

There are a number of things you can control in HTML that you can also control on the domain or protocol level. For example, aspects related to security, performance, or, as in the example, redirects (meta elements are infamous here), as well as around indexing and verification. Whenever that’s the case, you’re better off working with said domain or protocol level.

Why? Maintainability, for centralization through domain or HTTP configuration makes it a lot easier, faster, and more reliable to manage changes.

In this case, for example, most servers already respond to a request with a Last-Modified header. (The other two headers seem non-standard, but can be provided, too, if necessary.) The server the example site is on is no exception:

Last-Modified: Mon, 07 Oct 2019 21:21:47 GMT

The sample code gives room for speculation—what was the motivation to add all this meta markup, and why not use the standard Last-Modified format? However, the lesson is to employ HTTP headers if HTTP headers can be used. As with the optimized minimal example code, the best HTML is sometimes no HTML:

I> An anecdote: It’s theoretically possible—my last test dates back a while, and only Firefox passed it again—to also assign style sheets through HTTP headers. The way it works is described in the old HTML 4.01 spec: I> I> > Web server managers may find it convenient to configure a server so that a style sheet will be applied to a group of pages. The HTTP Link header has the same effect as a LINK element with the same attributes and values. Multiple Link headers correspond to multiple LINK elements occurring in the same order. I> I> This allows you to issue a header like I> I> I> Link: <https://example.com/default.css>; REL=stylesheet I> I> I> to be equivalent to: I> I> html I> <link rel=stylesheet href=https://example.com/default.css> I> I> I> This is the simplest way and the least work to create a style sheet reference—theoretically the only reference for an entire project. If this worked everywhere, you had my full recommendation to always and only set your default style sheet like this!