Share Your Work

SandyG1
投稿者 | Solutions Partner
投稿者 | Solutions Partner

Clear HubSpot cache bookmarklet

Hi guys,

 

I thought, I'd share with you a bookmarklet that I made for HubSpot caching resolutions.

 

What this does

Add this code as a book mark and then this will add a query string with a random number to clear cache. If it already exists it will update it. 

 

The query:  hsCacheBuster=XXX
This will help with a lot of caching issues as I have found out.
 
The code minified suitable for a javascript bookmarklet
1. Create a new bookmark and in the URL add the following code.
2. On your HubSpot page. (sandbox or live, whichever) click on the bookmark
3. Then upvote this if it has helped you out 🙂

javascript:void function(){!function(){var a=window.location.href;window.location=function(a,b,c){c||(c=window.location.href);var d,e=new RegExp("([%3F%26])"+a+"=.*%3F(%26|%23|$)(.*)","gi");if(e.test(c))return null==b%3F(d=c.split("%23"),c=d[0].replace(e,"$1$3").replace(/(%26|\%3F)$/,""),void 0!==d[1]%26%26null!==d[1]%26%26(c+="%23"+d[1]),c):c.replace(e,"$1"+a+"="+b+"$2$3");if(null!=b){var f=-1===c.indexOf("%3F")%3F"%3F":"%26";return d=c.split("%23"),c=d[0]+f+a+"="+b,void 0!==d[1]%26%26null!==d[1]%26%26(c+="%23"+d[1]),c}return c}("hsCacheBuster",Math.round(99999*Math.random()),a)}()}();
 
 
 
The code (unminified)
 
javascript: (function() {
    function UpdateQueryString(key, value, url) {
        if (!url) url = window.location.href;
        var re = new RegExp("([?&])" + key + "=.*?(&|#|$)(.*)", "gi"),
            hash;
    
        if (re.test(url)) {
            if (typeof value !== 'undefined' && value !== null) {
                return url.replace(re, '$1' + key + "=" + value + '$2$3');
            } 
            else {
                hash = url.split('#');
                url = hash[0].replace(re, '$1$3').replace(/(&|\?)$/, '');
                if (typeof hash[1] !== 'undefined' && hash[1] !== null) {
                    url += '#' + hash[1];
                }
                return url;
            }
        }
        else {
            if (typeof value !== 'undefined' && value !== null) {
                var separator = url.indexOf('?') !== -1 ? '&' : '?';
                hash = url.split('#');
                url = hash[0] + separator + key + '=' + value;
                if (typeof hash[1] !== 'undefined' && hash[1] !== null) {
                    url += '#' + hash[1];
                }
                return url;
            }
            else {
                return url;
            }
        }
    }
    var currentUrl = window.location.href
    window.location = UpdateQueryString('hsCacheBuster', Math.round(Math.random() * 999999), currentUrl);
})()

updateQueryString function src

1件の返信
sharonlicari
コミュニティーマネージャー
コミュニティーマネージャー

Clear HubSpot cache bookmarklet

Thank you for sharing @SandyG1! really interesting


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !