Tips and strategies to improve your website’s speed. Make your CMS Hub theme or site fast, and learn how to test your site’s speed.
module.css
only when a module is used on a page, and only loads it once regardless of how many instances of the module are on the page. By default, module.css
does not load asynchronously, but you can change this by including css_render_options in the module’s meta.json
file.
resize_image_url()
, uploading a non webp file that is already sized appropriately can help.img
elements contain height and width HTML attributes. This makes it so web browsers can intelligently optimize for cumulative layout shift during render time and also makes it so HubSpot can generate a srcset
for you.resize_image_url
to force images to be resized to a certain resolution.resize_image_url
to deliver images at sizes that make sense for the device.<link rel="preload" as="image" href="http://example.com/img_url.jpg">
within a require_head
tag. Use this technique sparingly, overusing it can actually hurt performance.img
and can predict it’s sizes at different viewport sizes, providing a custom srcset
and sizes
attribute can help. You can use theresize_image_url
function to generate the alternate sizes. A custom tailored srcset
and sizes
based on the actual usage of the img
element, will likely be more effective than the HubSpot generated one, but the automatically generated one is better than nothing.img
element decoding="async"
. This tells the browser that it can start loading other content on the page at the same time as it’s loading and processing the image.loading="lazy"
. This tells the browser it can wait to render and process the iframe until the user is close to displaying it on screen.<head>
can also be a problem as javaScript is render blocking resource by default. Additionally JS is running on the visitors device, meaning it is limited to the resources that device has.
<head>
by default. You can remove it entirely in Settings > Website > Pages, or upgrade to the latest version of jQuery. Take care when changing these settings on older websites if you did not build them, they may have been built reliant on jQuery or based on jQuery loading in the header.</body>
to prevent render blocking. You can use require_js
to load js for modules or templates only when needed and without accidentally loading the javascript multiple times for multiple instances of a module.<details>
and <summary>
. For modals use <dialog>
.require_js
, use async
or defer
attributes to improve page performance.setTimeOut
and/or RequestAnimationFrame
any code that needs to happen in response to the user interaction, but can happen later or is not going to be visible to the user right away.