Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created August 24, 2011 16:49
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakearchibald/1168514 to your computer and use it in GitHub Desktop.
Save jakearchibald/1168514 to your computer and use it in GitHub Desktop.
Preventing images & other media downloading
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script id="whatever">document.write('<!'+'--')</script>
<img src="filth.jpg" />
<!---->
<script>
// filth.jpg will start loading now for users without js.
// However, it'll appear inside a comment for js users, so won't load.
// Then you can do...
var commentedHtml = document.getElementById('whatever').nextSibling.nodeValue.slice(0, -4);
// Now you can set that as the innerHTML of something and the img will load.
// Perfect for scrolly-load situations, or if you wanted to pipe 100 thumbnails
// down one http connection, whatever.
// Props to @pornelski who came up with the basis of the solution.
// It's as dirty as it is awesome.
</script>
</body>
</html>
@aaronpeters
Copy link

Awesome indeed!

@ahume
Copy link

ahume commented Oct 31, 2011

Crikey. There's one.

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