YodaSpow / EmailDevTools

EmailTools
https://codepen.io/spowart/details/abWzBwR
7 stars 1 forks source link

Remove ESP `?<%= cC %>` Clear cache EJS query BEFORE clear-cache for browser images (jquery method) #38

Closed YodaSpow closed 5 years ago

YodaSpow commented 5 years ago

Is your feature request related to a problem? Please describe. Clear cache for ESP (?<%= cC %>) is added ad-hoc after images src path.

Describe the solution you'd like Remove the ?&lt;%= cC %&gt; before running the page loaded script for browser-based clear-caching

Describe alternatives you've considered Maybe it could just be regex as find and remove: ?&lt;%= cC %&gt;

Additional context Code base can then work with the intended result as the redundant EJS variable ?&lt;%= cC %&gt; is blocking the query function for clearing locally using EmailTools.

YodaSpow commented 5 years ago

Have some code here: https://codepen.io/spowart/pen/vPxdwM

var versionUpdate = (new Date()).getTime(); // Works in AC

/* Doesnt work in Adobe Campaign*/
var imgs = document.querySelectorAll('img'), len = imgs.length;
for (var i=0; i<len; i++) {
    //imgs[i].style.background = "green";
    var s = imgs[i].src;
    imgs[i].src = s + "?" + versionUpdate;
    console.log(imgs[i].src);
}
YodaSpow commented 5 years ago

Maybe it's possible to do as regex instead: https://codepen.io/spowart/pen/XGeOYL?editors=1010

YodaSpow commented 5 years ago

Info: https://www.bounteous.com/insights/2015/04/17/strip-query-parameters-google-analytics/

YodaSpow commented 5 years ago

Got it working:

  $('img').not(cache).each(function(){
    /* Remove AC bespoke IMG variable: ?&lt;%= cC %&gt; */
    this.src = this.src.replace(/(\?&lt;%= cC %&gt;|\?%3C%=%20cC%20%%3E)/g, ""); 

    var versionUpdate = (new Date()).getTime();
    this.src = this.src + '?' + versionUpdate;
  });

Tested it here: regexr.com/4a22f

YodaSpow commented 5 years ago

Updated as of this commit: f0068cf4538a9b83d2eabf60abfbf5a8d0f86681

Adobe Campaign: (AC pre-send to Inbox) LEFT: AC Pre-Send time ----------- RIGHT: Sent from AC to Litmus code view https://www.diffchecker.com/OywA6STg

EmailTool (Local HTML, source code vs computed JS) LEFT: Adobe Campaign ready code: cC variable ----- RIGHT: Browser running EmailTools as computed JS https://www.diffchecker.com/t9EYgWkC