Skip to content

Instantly share code, notes, and snippets.

@ivan-kleshnin
Last active June 29, 2021 04:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-kleshnin/b6206270299b6bc10798c261283abe7d to your computer and use it in GitHub Desktop.
Save ivan-kleshnin/b6206270299b6bc10798c261283abe7d to your computer and use it in GitHub Desktop.

1. HTTP Performance

1.1 Reduce number of HTTP Requests

  • Use HTTP/2
  • GraphQL
  • CSS sprites
  • Bundling
  • Browser Caching
  • Cache Busting
  • Proper SSL setup

1.2 Reduce size of HTTP Responses

  • Minification
  • GZIP
  • CSS shortcuts (reduce file size)
  • CSS vendor props (increase file size)
  • Reduce cookie size (simple user ids vs JW tokens)
  • SVG vs Images
  • Sprites

1.3. Lazy load everything

  • Bundle splitting
  • Lazy load images

2. Rendering Performance


Asynchronous and deferred execution of scripts are more important when the <script> element is not located at the very end of the document. HTML documents are parsed in order, from the first opening element to it's close. If an externally sourced JavaScript file is placed right before the closing element, it becomes much less pertinent to use an async or defer attribute. Since the parser will have finished the vast majority of the document by that point, JavaScript files don't have much parsing left to block.

For script files that are not dependent on other files and/or do not have any dependencies themselves, the async attribute is particularly useful. Since we do not care exactly at which point the file is executed, asynchronous loading is the most suitable option.

Use on scripts like GA (async) and DOM-depending scrips (defer) which for some reasons are located not before </body>


  • 3 steps: Fetching -> Parsing -> Execution (-> Rendering (HTML))
  • JS fetching blocks HTML & CSS parsing (but not fetching)
  • CSS fetching blocks JS execution (but not fetchin & parsing)
  • CSS also blocks HTML rendering (DOM construction awaits JS & CSSOM) (unless @media or better media="print")

CSS at the TOP scripts at the BOTTOP basic model takes the above into account:

  1. fetch CSS -- non blocking for HTML
  2. parse CSS -- the same
  3. execute CSS -- blocks HTML rendering, blocks JS execution. Both can be not affected.
  4. fetch, parse, execute JS -- everything else is done

New speculative parsing (keep parsing even while JS executes) changes some of the above (basically it assumes there won't be "bad" types of document.write). If JS scripts are at the end – it doesn't matter

<link rel="preload" href="font.woff" as="font" crossorigin> - fonts should be preloaded (as they heavily affect rendering)

Font imports may be buried inside CSS and browser won't load them while it's busy with selectors. So it makes sense to start loading them earlier. I would use it for heavy assets.

preload vs async scripts -- preload doesn't delay onload event

preload vs defer vs async -- the last two work ONLY for scripts. preload can behave like async or defer and it's controlled by YOU

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