Use JavaScript code to prevent browser caching

If a random number cannot be generated at the server level, you can use JavaScript code to generate a string at the client (browser) level. The following examples illustrate how to prevent browser caching (also known as implementing cache busting) with a standard image tag or Iframe/JavaScript tag.

These are only examples. If you want to use this code, please adapt it for your specific HTML tags. You must paste the actual tags into the appropriate places in these examples.

Example of standard image tags

<SCRIPT LANGUAGE="JavaScript">
<!-- hide from non-JavaScript browsers
var axel = Math.random() + "";
var num = axel * 1000000000000000000;
document.writeln('<A HREF="http://ad.doubleclick.net/jump/N409.somesite/B470;sz=468x60;ord='+ num +'?"><IMG SRC="http://ad.doubleclick.net/ad/N409.somesite/B470;sz=468x60;ord='+ num +'?" BORDER=0 WIDTH=468 HEIGHT=60 ALT="Click Here!"> Click Here!</A>');
// end hide from browsers -->
</SCRIPT>
<NOSCRIPT>
<A HREF="http://ad.doubleclick.net/jump/N409.somesite/B470;sz=468x60;ord=[timestamp]?">
<IMG SRC="http://ad.doubleclick.net/ad/N409.somesite/B470;sz=468x60;ord=[timestamp]?" BORDER=0 WIDTH=468 HEIGHT=60 ALT="Click Here!"> Click Here!</A>
</NOSCRIPT>

Example of JavaScript tags

<SCRIPT LANGUAGE="JavaScript">
ord=Math.random();
ord=ord*10000000000000000000;
document.write('<SCR' + 'IPT LANGUAGE="JavaScript" SRC="http://ad.doubleclick.net/adj/N1234.site.com/B12345;sz=468x60;ord='+ord+'?"><\/SCR' + 'IPT>');
</SCRIPT>
<NOSCRIPT>
<A HREF="http://ad.doubleclick.net/jump/N1234.site.com/B12345;sz=468x60;ord=123456789?" TARGET="_blank">
<IMG SRC="http://ad.doubleclick.net/ad/N1234.site.com/B12345;sz=468x60;ord=123456789?" WIDTH="468" HEIGHT="60" BORDER="0" ALT="Click here..."></A>
</NOSCRIPT>

Example of Iframe/JavaScript tags

<SCRIPT LANGUAGE="JavaScript">
<!-- hide from non-JavaScript browsers
var axel = Math.random() + "";
var num = axel * 1000000000000000000;
document.writeln('<IFRAME SRC="http://ad.doubleclick.net/adi/N409.somesite/B470;sz=468x60;ord='+ num +'?" WIDTH=470 HEIGHT=62 MARGINWIDTH=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no BORDERCOLOR="#000000">');
document.writeln('<SCR'+'IPT language="JavaScript1.1" SRC="http://ad.doubleclick.net/adj/N409.somesite/B470;abr=!ie;sz=468x60;ord='+ num +'?"></SCR'+'IPT></IFRAME>');
// end hide from browsers -->
</script>
<noscript>
<A HREF="http://ad.doubleclick.net/jump/N409.somesite/B470;abr=!ie4;abr=!ie5;sz=468x60;ord=?">
<IMG SRC="http://ad.doubleclick.net/ad/N409.somesite/B470;abr=!ie4;abr=!ie5;sz=468x60;ord=?" BORDER=0 WIDTH=468 HEIGHT=60 ALT="Click Here!">Click Here!</A>
<noscript>

Example of standard tags for impression-tracking only

<SCRIPT LANGUAGE="JavaScript">
ord=Math.random();
ord=ord*10000000000000000000;
document.write('<IMG SRC="http://ad.doubleclick.net/ad/N1234.site.com/B12345;sz=468x60;ord='+ord+'?" WIDTH="468" HEIGHT="60" BORDER="0">');
</SCRIPT><NOSCRIPT><IMG SRC="http://ad.doubleclick.net/ad/N1234.site.com/B12345;sz=468x60;ord=123456789?" WIDTH="468" HEIGHT="60" BORDER="0"></NOSCRIPT>

Was this helpful?

How can we improve it?

Need more help?

Try these next steps:

true
2024 Privacy Readiness guide

Prepare for a world without third-party cookies and unlock the AI
opportunity by adopting a durable measurement setup.
Start Today

Search
Clear search
Close search
Main menu
8267263568679810886
true
Search Help Center
true
true
true
true
true
69192
false
false