Last active
December 12, 2015 07:48
-
-
Save darobin/4739457 to your computer and use it in GitHub Desktop.
Who needs srcset? Who needs <picture>? Not the AppCache people we don't!
This file contains 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> | |
<!-- | |
- controllerpath should default to /*, it's just the typical thing | |
- controllersync ensures the controller is always there | |
--> | |
<html controller="respimg.js" controllerpath="/*" controllersync> | |
<!-- ... --> | |
<img src='my-shiny-donkey.png#resp-me'> | |
</html> |
This file contains 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
// this all assumes no resizes | |
// if you need resizes, you can handle it using postMessage and a resize handler | |
// implementation left as an exercise to the reader | |
this.onrequest = function (e) { | |
if (e.request.url.match(/#resp.me/)) { | |
var size = doSomeMagicToPickRightSize() | |
, url = e.request.url.replace(/#resp.me/, "").replace(/(\.\w+)$/, size + "$1") | |
; | |
// XXX this could possibly use a better API | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", url); | |
e.preventDefault(); | |
e.respondWith(xhr); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice. However, manually having to deal with resizes etc with postmessage etc will inevitably lead to libraryitis and cargo-cult code. I agree with Yoav: we still need a simple, declarative way to do this.