Optimizing your CMS Hub site for performance

Last updated:
  • Marketing Hub
    • Professional or Enterprise
  • CMS Hub
    • Professional or Enterprise

Great User Experience (UX) is a factor of content quality, speed, security and accessibility. Optimizing for these generally also improves Search Engine Optimization (SEO).

Better performance is all about providing a better experience for end users. Achieving better performance is all about solving for your individual site's bottlenecks.

Start with a good foundation

It's easier to build from a great foundation that was built with performance in mind, than trying to fix performance issues later. A metaphor, building a fast car from the ground up, is easier than buying a slow car and trying to make it fast.

The HubSpot CMS Boilerplate was built to be fast, and encourage best practices. See the GitHub README to see the current scores in lighthouse and website grader.

When building from the boilerplate you know that without any code you've added, it achieves those scores. That means you can focus your attention on the code you added on top of the boilerplate.

Common website performance bottlenecks

Most web performance optimization techniques and best practices are not HubSpot specific. This is because most website performance bottlenecks are not HubSpot specific. 

Most performance issues fall into a couple of categories, rendering and loading.

  • Loading performance is the efficiency of transferring all of the files needed for your web page to the user's browser.
  • Rendering performance is the efficiency for the browser to take everything it downloaded and display the end result to the user.



Images are prevalent on almost every page on the web. Images are usually the largest files on a page. The more images, and the larger the images, the longer your page will take to load. Animated images such as gifs and animated webp, also take up more space than non animated images of the same size. Some image formats also are more performant than others, and better for certain scenarios.

What you can do

  1. The most important thing you can do is optimize your images for the web. Image optimization is very much a shared responsibility among both content creators and developers.
  2. Use fewer images per page.
  3. Use the right image format for the scenario.
  4. Use Scalable Vector Graphics (SVGs) where possible. SVGs can scale in size infinitely without losing quality. Inlining your SVGs makes sense when you are making animations. In static graphics creating an SVG sprite sheet or simply treating it as a normal img element, or background image is typically better for performance.
  5. Intelligently lazy load images.
  6. Make sure img elements contain height and width HTML attributes. This makes it easier on browsers during render time and also makes it so HubSpot can intelligently add a srcset for you. Not only does HubSpot help optimize, but web browsers can intelligently optimize for cumulative layout shift when you provide width and height. 
  7. Use resize_image_url to force images to be resized to a certain resolution.

Autoplaying video

Video backgrounds can certainly set a website apart. Unfortunately they come at a cost. Video backgrounds are often used for website headers. When a video auto-plays, it means the browser needs to start loading the video right away. This can be especially problematic for users on slower connections or using cellphone data. 

What you can do

  1. Avoid using autoplaying video. If what you're showing is a background animation, consider using CSS animations or javascript animations. If you must display an autoplaying video:
  2. Choose a reasonable resolution for the video based on your use-case, and apply an effect over the video to make a lower resolution less noticeable.
  3. Make sure the video scales in quality based on the device and connection, the best way to do this is using a video sharing service like YouTube or Vimeo.
  4. Disable autoplaying on mobile, show a fallback image instead.

Heavy JavaScript use

JavaScript is useful for adding interactivity to your website. Loading a lot of JavaScript code in general increases the file size of the javascript files and the amount of time it takes for the browser to render interactive elements. Loading JavaScript in the <head> can also be a problem as javaScript is render blocking resource by default.

What you can do

  1. When HubSpot's CMS first came out jQuery was loaded in the <head> by default. You can both move jQuery to your footer, as well as remove it entirely in Settings > Website > Pages. 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.
  2. Ensure javascript is loaded just before the </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.
  3. Consider refactoring your javascript to be more efficient. Use fewer javascript plugins, use semantic HTML where it can help. For example for dropdowns, use <details> and <summary>. For modals use <dialog>.
  4. If you're using a giant javascript library just for a few small features, consider using vanilla javascript or loading a subset of the library if possible.
  5. Use require_js and linked javascript files to load javascript only when necessary and only once per page.
  6. If loading external resources use preconnect and DNS prefetch appropriately to deliver a faster experience.
  7. Limit the number of tracking scripts you use.

Code Alerts

Code Alerts is a CMS Hub Enterprise feature which acts as a centralized overview of issues that are identified inside of your HubSpot CMS website. Fixing issues that are identified in Code Alerts can help to optimize your website performance. Issues identified comprise several different areas from HubL limits, to why CSS is not automatically combining.

Learn more about Code Alerts.


What does HubSpot handle for you?

Most of the performance/speed best practices are not HubSpot specific. HubSpot's CMS automatically handles many common performance issues for you. Here's a list of some of these optimizations:


Additional resources for improving your site's speed

There is a lot that can be done to optimize a site for speed and many of the topics warrant a further breakdown. We've compiled some great resources we encourage you to check out when working on optimizing your site.