CMS Development

SMetcalf
Participant

Page loading old code

SOLVE

I'm having a huge issue. I'm developing a website theme with local development and using the HubSpot CLI to push code into a developer's account. I use 'hs-upload' to push the code whenever I make an update. I used to use 'hs-watch' but that makes this issue I'm about to explain even worse. 

This is the exact issue:

I make some changes to the code, I use the  'hs-upload' to push the code. I refresh the webpage, everything looks good, the code is updated. Then I click on a link in the page to go to another page, and when I see the new page loaded, it looks terrible. It's clearly missing a bunch of styles (one's that I added since using the code, but sometimes other styles are missing as well). From then on no matter what page I'm on, it's missing a bunch of styles. It continues like this until I rerun 'hs-upload' then everything is fixed. Sometimes right out of the box after pushing the code, when I refresh the styles are missing as well. 

I've never had this problem with other templates I've created on HubSpot. It's clear that I'm getting all the correct HTML, but the javascript and CSS are just missing, and it's persistent until I push the code again. It makes it incredibly difficult to share the site with the client, because I'm never sure if it's going to mess up, and they're going to see the page without a bunch of styles. 

This happens completely randomly. I've even double-checked that the files have all the styles and code in the design tools and they're always there. I suspect that it has something to do with some sort of cache that is not being updated sometimes. 

 

What I know is not the cause: 

- it's not that I'm pushing the code and it's not being uploaded to Hubspot. When I push, and this issue happens, I look in the design tools and the updates are always there. 

- it's not my browser caching the page or something wacky like that. I've had to get into the habit of doing hard reloads on the browser to actually see the changes take place at all, so I know it can't be a browser thing. I've also looked on my phone and a second computer, and the styles are still not updated sometimes. 


0 Upvotes
1 Accepted solution
albertsg
Solution
Guide

Page loading old code

SOLVE

Hi @SMetcalf , we had similar issues and in our case was cache related (and from time to time we still have this issue). 

Sometimes, hard reloading the page is not enough.

 

What we did is to add a "cache buster" when loading our files into HTML using a random variable or the timestamp. So everytime we load the page, we have our assets loaded with ?somenumber and that will stop the cache issue from happening. 

 

This link might help: https://crrollyson.medium.com/add-cache-buster-to-hubspot-hubl-get-asset-url-with-unixtimestamp-with... 

Also, make sure you are using the latest CLI version (https://developers.hubspot.com/docs/cms/developer-reference/local-development-cli#upgrade), we also had issues with CSS and JS files not being uploaded and it was fixed after updating our CLI.



Did my answer help you? Mark it as a solution

You also connect with me on LinkedIn or Twitter

View solution in original post

3 Replies 3
SMetcalf
Participant

Page loading old code

SOLVE

This worked, thanks a lot! and 'hs watch' is working perfectly again too!
The only thing I ended up doing differently than the medium article instructions is to put the timestamp into the require_js / require_css function rather than a script/link tag (which was causing an issue)

 

{{ require_js(get_asset_url('../../js/main.js') + '?' + unixtimestamp()) }}
{{ require_css(get_asset_url('../../css/main.css') + '?' + unixtimestamp()) }}

 

 

0 Upvotes
albertsg
Solution
Guide

Page loading old code

SOLVE

Hi @SMetcalf , we had similar issues and in our case was cache related (and from time to time we still have this issue). 

Sometimes, hard reloading the page is not enough.

 

What we did is to add a "cache buster" when loading our files into HTML using a random variable or the timestamp. So everytime we load the page, we have our assets loaded with ?somenumber and that will stop the cache issue from happening. 

 

This link might help: https://crrollyson.medium.com/add-cache-buster-to-hubspot-hubl-get-asset-url-with-unixtimestamp-with... 

Also, make sure you are using the latest CLI version (https://developers.hubspot.com/docs/cms/developer-reference/local-development-cli#upgrade), we also had issues with CSS and JS files not being uploaded and it was fixed after updating our CLI.



Did my answer help you? Mark it as a solution

You also connect with me on LinkedIn or Twitter

siderole
Participant

Page loading old code

SOLVE

Just seeing, but wanted to say I appreciate you sharing that link! 

0 Upvotes