When declaring external files in HTML such as .css or .js, is there a correct order in which to place the link\'s attributes? For example:
Any order is valid HTML but just out of curiosity I wondered whether the external file would get downloaded sooner if the href
attribute was first.
I created 3 documents each one had a with the
href
attribute positions differently, it took 200 extra attributes to be able to see a difference. In Chrome at least, the sooner you put the href
the better. rel
should also be put sooner as this helps the browser to decide whether to download the file.
Delay range from ("Empty Cache and Hard Reload" to start "Queueing") * 10
href
before extra attributes : 17.5ms - 23.5mshref
after extra attributes : 21.5ms - 27.5msEven with 200 additional attributes the extra delay was a maximum of 10ms (27.5-17.5).
When working on the front-end I always believed there was no such thing as an useless micro-optimisation, but this really is one.
Document
Document
Document