Pritesh Kiri
Pritesh Kiri

@PriteshKiri

11 Tweets 1 reads Oct 24, 2022
๐Ÿ“ŒHave you ever seen this rel attribute in link tags with the value of preload??๐Ÿค”๐Ÿค”
Wondering how it works and why is it used ??
Let me explain this concept in simple words in this thread ๐Ÿงต
โžก๏ธ What does preload do?
=> In simple terms, It helps the browser know about important resources that will be needed by the page, without delaying the page's "onload" event.
CODE:
<link rel="preload" href="font.com" as="font" />
โžก๏ธ How does it work?
=> Resources loaded via <link rel="preload"> are stored locally in the browser, and are effectively inert until theyโ€™re referenced in the DOM, JavaScript, or CSS.
=> The "as" attribute used in <link> element, is to give the browser more context about the destination of the preloading request being made.
=> This additional information ensures that the browser will set appropriate request headers and requests higher priority.
โžก๏ธ What is the benefit of pre-load?
=> The browser can set the right resource priority, hence will load accordingly, and will not delay more important resources, nor tag along behind less important resources.
=> The browser can make sure that the request is subject to the right Content-Security-Policy directives, and doesnโ€™t go out to the server if it shouldnโ€™t.
=> The browser can send the appropriate Accept headers based on the resource type. (e.g. advertise support for โ€œimage/webpโ€ when fetching images)
=> The browser knows the resource type, thus determines if resource could be reused for future requests that need the same resource.
=> Thus, ultimately it is helpful in improving website performance.
โžก๏ธ Now the question arises, how will you know what should be preloaded?
Please find the thread below to know the answer๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡
That's a wrap!!!!!๐ŸŽ
I hope you learned something new today ๐Ÿš€
Stay tuned and keep practicing๐Ÿ™Œ
Thanks for reading this thread till the end ๐Ÿ˜ƒ
๐Ÿ”– Bookmark this thread for the future
๐Ÿ”ƒ Retweet the first tweet
๐Ÿš€ Follow @PriteshKiri for more daily web development tips and tricks
#codewithcoffee #codewithcoffeeindia

Loading suggestions...