Skip to content

Instantly share code, notes, and snippets.

@shivam1283
Last active March 10, 2022 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shivam1283/12cc2b330e12e97e69eecb2c2077ca72 to your computer and use it in GitHub Desktop.
Save shivam1283/12cc2b330e12e97e69eecb2c2077ca72 to your computer and use it in GitHub Desktop.
[Web Performance]

preload

<link rel="preload" href='./style.css' >

Advantages

  • The preload property enables browser to load resources tha will be required very soon in the page rendering lifecycle, before the main rendering kicks in.
  • The call for resources can be prioritised.
  • Store in the cache for future requests.

type

<link type="text/css" rel="preload" href='./style.css' >

Advantages

  • The resource can be preloaded
  • The browser can check if it supports such type of resource and should it load it

Source : MDN Docs

Including MIME(Mutlimedia) type

Background images and media can be preloaded in order to render images according to screen sizes( if images are conditionally rendered from JS).

`

<title>Responsive preload example</title>

My site

<script> var mediaQueryList = window.matchMedia("(max-width: 600px)"); var header = document.querySelector('header'); if (mediaQueryList.matches) { header.style.backgroundImage = 'url(bg-image-narrow.png)'; } else { header.style.backgroundImage = 'url(bg-image-wide.png)'; } </script>

`

prefetch

The resources are loaded which might be needed on the next page. These resources are prioritised below preload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment