- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
A place to gather resources, issues, and solutions to optimize website speed
Jul 15, 2020 3:15 AM - edited Jul 16, 2020 11:46 AM
Optimizing a Hubspot site to load quickly is difficult at the moment. Good solutions are scattered and the current documentation has gaps. Let's use this post to donate solutions that work and start a conversation to fix what doesn't.
This guides needs two sections:
- Working solutions that everybody can do
- Unique Hubspot issues
1. Working Solutions
If you're new, start with the Hubspot CMS-Boilerplate—it has all the answers. Carefully step through the docs until you're comfortable with local development (don't forget Github Actions).
Snippets Coming Not That Soon
- Webpack config
- Hubspot Autouploader
- SASS/SCSS
- Image optimization
- Image deferral
- Critical path CSS
- Videos
- Font optimization
Researching and Need Help
- Deferring Hubspot analytics
- Separate CSS/JS bundles at page level
2. Unique Hubspot Issues
Some features (like tracking codes) are always loaded—Hubspot without tracking analytics isn't Hubspot. Other features (like contact forms) are optional but require creative implementations to prevent nerfed PageSpeed scores.
The Worst (Only?) Offenders
1. Hubspot Forms
Embedding a Hubspot form can drop your pagespeed score by up to 20% on mobile. Why do the form and "//js.hsforms.net/forms/v2.js" script have such a huge cost?
If you are 100% sure that your form will appear "below the fold", this is a working solution:
<!-- Add somewhere in your HTML --> <div id="form-holder"></div>
/******************** Add somewhere in your JS ******************/ function userScroll() { var hsform = document.createElement('script'); hsform.src='//js.hsforms.net/forms/v2.js'; hsform.async = true; document.head.appendChild(hsform); const currentScroll = window.pageYOffset; if (currentScroll > 0) { if (window.hbspt) { window.hbspt.forms.create({ portalId: "[your-portal-id]", formId: "[your-form-id]", target: '#form-holder' }); window.removeEventListener('scroll', userScroll, false); } } } document.addEventListener('readystatechange', event => { if (event.target.readyState === 'complete') { window.addEventListener('scroll', userScroll, false); } });
Please reply if you have a better solution or have an idea to make this work for forms that appear "above the fold".
Jon McLaren pointed out some issues with this solution in the developer Slack channel.
- Scroll is not the best trigger for performance reasons
- Not a good idea to depend on scrolling for important content
- This could trigger when a lot of other things are also happening
Other posts talking about this:
2. Hubspot Chat
It's bad but I don't have numbers ready yet.
3. Mystery Files
It's not clear if these files are needed but they are automatically included. As far as I know, the following files are always loaded and cannot be removed:
- ...scriptloader/8020292.js (802029s.hs-sites.com)
- ...159.../8020292.js (js.hs-analytics.com)
- /8020292.js (js.hs-banner.com)
- /bundles/project.js (static.hsappstatic.net)
- /collectedforms.js (js.hscollectedforms.net)
- sometimes common.js (no longer forced)
- sometimes layout.js (no longer forced)
4. Cache Policy
Should we be able to define custom cache policies to help repeat visits load faster? Is there a downside to setting these to far in the future and using a hash to load new versions?
5. Which files are required for a locally developed Hubspot site to publish? Can they be combined to make fewer HTTP requests?
6. Does it ever make sense to build a Hubspot site that doesn't include standard Hubspot analytics?
7. Which of these mystery files am I actually generating myself by accident? Can I prevent them from loading?
8. Are there any other hidden files or bloated files that we don't need 100% of the time?
9. Maybe Google PageSpeed scores aren't a good reflection of most user experiences on your site?
---------------------------------------------
Reading List
Hubspot Guides
- https://developers.hubspot.com/docs/cms/guides/speed
- https://knowledge.hubspot.com/reports/how-do-i-improve-the-page-load-time-for-my-website
Blog Posts
- https://blog.hubspot.com/marketing/how-to-reduce-your-websites-page-speed
- https://developers.hubspot.com/blog/how-we-improved-page-speed-on-hubspot.com
Hubspot Courses
Good To Know
Last Updated: 7/16/20 (Published but in progress...)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content