Is there a correct order that attributes should be listed in when linking external files?

前端 未结 2 1472
隐瞒了意图╮
隐瞒了意图╮ 2021-01-13 13:08

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:



        
2条回答
  •  温柔的废话
    2021-01-13 13:39

    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

    • No extra attributes : 19.5ms - 25ms
    • href before extra attributes : 17.5ms - 23.5ms
    • href after extra attributes : 21.5ms - 27.5ms

    Even 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
    	
    
    
    	
    
    

提交回复
热议问题