Created
August 24, 2011 16:49
-
-
Save jakearchibald/1168514 to your computer and use it in GitHub Desktop.
Preventing images & other media downloading
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crikey. There's one.