Skip to content

Instantly share code, notes, and snippets.

@phelma
Last active June 30, 2023 12:32
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 phelma/9efd45fb4fd5275090bf9cc8eaeb570a to your computer and use it in GitHub Desktop.
Save phelma/9efd45fb4fd5275090bf9cc8eaeb570a to your computer and use it in GitHub Desktop.
performance.now() conference notes

Performance Now Conference

Resource Loading

  • Resource Hints
    • <link rel="preload" href="stlye.css" as="style" >
      • rel="dns-prefetch" browser resolves dns asap
      • rel="preconnect" browser resolves dns & TCP handshake ( & TLS negotiation) asap
      • rel="prerender" loads all resources & renders page (like in hidden tab)
      • rel="prefetch" browser requests item and caches - intended for next page resources
      • rel="preload" browser requests item and caches - intended for current page resources
        • Can be added to HTTP Headers: Link: <thing_to_load.js>;rel="preload";as="script"
        • Nginx can be configured to automatically add these with HTTP/2 server push
  • HTTP/2 Server Push
  • 3rd Party

Images

  • Progressive encoding
    • Image can render before it has fully loaded
    • Image looks OK at 15%
  • MozJPEG
  • AV1 Video offers best image compression - not well supported yet
    • could embed a single frame AV1 <video> for a large hero image
    • A new image format will do this
  • Fastest image delivery server (cloudflare edge worker)
    1. Recieve request
    2. Send first 512 bytes (includes height / width etc)
    3. Wait 20ms
    4. Send first 15% of file (enough to render a low quality image)
    5. Wait for other files to have been loaded
    6. Send the rest of the image

Javascript

  • Bit field - for storing large number of bools (which are 8Bytes each in JS)
  • Google Closure compiler (and ADVANCED_OPTIMMIZATIONS)
  • Tree shaking / Dead code elimination

Protocols

  • HTTP/2
    • Header Compression
    • Multiplexing
    • Server Push
    • Requires TLS
  • Head of line blocking (client needs to reviece all packets in order)
  • Internet infrastructure is old/brittle, new technologies must use existing protocols
  • QUIC (now officially HTTP/3)

Fonts

  • WOFF2, offers best compression, ~82% supported, still need fallbacks (ie11 & android browser)
  • Link rel={preconnect,preload}
  • Self Host (same origin reduces connect time)
  • Font Display Timeline
    • Font block - if font is not loaded text is shown invisible
    • Font swap - if font is not loaded fallback font rendered
  • CSS font-display https://font-display.glitch.me/
    • font-display: block; show invisible until font loads
    • font-display: swap; no invisible text, show fallback immediately then font when it is loaded
    • font-display: fallback; show invisible and wait 100ms for font, if still not loaded then show fallback, then show font
    • font-display: optional; show invisible for 100ms, then show fallback
  • Font synthesis, only load base font weight & style at page load
    • This can be used to show text, and minimise motion during reflow when page loads
  • Font Loading API https://developer.mozilla.org/en-US/docs/Web/API/CSS_Font_Loading_API
  • Subsetting
  • Network information API https://developer.mozilla.org/en-US/docs/Web/API/Network_Information_API
  • Variable fonts (allow variables in single font, quite heavy)

UI Performance

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