Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pdf documents will have a cache busting
<script type="text/javascript">
jQuery(document).ready(function($){
// All pdf documents will have a cache busting
// string added to its url
$("a[href $='.pdf']").click(function(){
var now = new Date().getTime();
$(this).attr('href', $(this).attr('href') + '?cache=' + now );
});
});
</script>
@hillbilly

This comment has been minimized.

Copy link
Owner Author

@hillbilly hillbilly commented Jan 19, 2014

I had a need to cache a pdf file and came up with this idea.

It takes the link to the pdf file and adds a random number to the query that will stop the browser from caching the file, in this case a pdf.

It can easily be modified for any link type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment