Created
November 16, 2012 10:50
-
-
Save imaya/4086371 to your computer and use it in GitHub Desktop.
zlib.js gunzip demo
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> | |
<html> | |
<head> | |
<script src="gunzip.min.js"></script> | |
<script> | |
(function(global) { | |
var css = './gunzip.demo.css.gz'; | |
var xhr = new XMLHttpRequest(); | |
xhr.open('GET', css, true); | |
xhr.addEventListener('load', function(ev) { | |
var link = document.createElement('link'); | |
var plain = | |
new Zlib.Gunzip(new Uint8Array(ev.target.response)).decompress(); | |
link.setAttribute('rel', 'stylesheet'); | |
link.setAttribute('type', 'text/css'); | |
link.setAttribute( | |
'href', | |
global.URL.createObjectURL(new Blob([plain], {type: 'text/css'})) | |
); | |
document.head.appendChild(link); | |
}, false); | |
xhr.responseType = 'arraybuffer'; | |
xhr.send(); | |
})(this); | |
</script> | |
</head> | |
<body> | |
GZIP で圧縮した CSS ファイルを JavaScript で展開して使う | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment