Jens Oliver Meiert

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

Post from January 13, 2020 (↻ August 6, 2021), filed under .

The following is a (slightly modified) chapter from Upgrade Your HTML, which is “all about picking examples of HTML in the wild, and explaining how to make that code better.” You can get an inexpensive copy at Leanpub as well as at Amazon.

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

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

<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">

In the case of the markup above, 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

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


An Anecdote

The cover of “Upgrade Your HTML.”

It’s theoretically possible—my last test dates back a while, and only Firefox just passed it again—to also assign style sheets through HTTP headers. The way it works is described in the old HTML 4.01 spec:

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.

This allows to issue a header like

Link: <>; REL=stylesheet

to be equivalent to:

<link rel=stylesheet href=>

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!

Needless to say, there may be exceptions to the rule, the most obvious one being the case when HTTP headers can’t be set. For a softer version of the rule, replace “use” with “prefer.”

More? Upgrade Your HTML. (If you’re interested in web development and HTML and CSS quality overall, consider the book bundle that also includes CSS Optimization Basics and The Web Development Glossary.)

Tweet this? (If it changed your life, you delight me with a coffee.)

About Me

Jens Oliver Meiert, on April 29, 2020.

I’m Jens Oliver Meiert, and I’m an engineering manager and author. I’ve worked as a technical lead for Google, I’m close to the W3C and the WHATWG, and I write and review books for O’Reilly. Other than that, I love trying things, sometimes including philosophy, art, and adventure. Here on I share some of my views and experiences.

If you have questions or suggestions about what I write, please leave a comment (if available) or a message.

Read More

Have a look at the most popular posts, possibly including:

Looking for a way to comment? Comments have been disabled, unfortunately.

Cover: The Web Development Glossary.

Perhaps my most comprehensive book: The Web Development Glossary (2020). With explanations and definitions for literally thousands of terms from Web Development and related fields, building on Wikipedia as well as the MDN Web Docs. Available at Apple Books, Kobo, Google Play Books, and Leanpub.

Stay up-to-date? Follow me by feed or on Twitter.

Found a mistake? Email me,

You are here: HomeArchive2020 → If It Can Be Done Using an HTTP Header, Use an HTTP Header

Last update: August 6, 2021

Professional frontend developers produce valid HTML and CSS.