Re: [whatwg] HTTP status code from JavaScript

On 25 May 2014, at 09:58, Tobie Langel <tobie.langel@gmail.com> wrote:

> 
>> * Adding inline JS <script> slows down the page load.
> 
> In that case, use a meta tag:
> 
> <meta name=http-status content=404>
> 
> Then in JS:
> 
> var status = parseInt(document.querySelector("meta[name=http-status]").getAttribute("content"));

Since `http-status` is not a registered metadata name (http://wiki.whatwg.org/wiki/MetaExtensions) it might be better to use a custom `data-*` attribute. It could be added to any element, e.g.

    <body data-http-status=404>

Then in JavaScript:

    var status = Number(document.body.dataset.httpStatus);

Received on Sunday, 25 May 2014 08:21:57 UTC