Skip to content

Instantly share code, notes, and snippets.

@imaya
Created November 16, 2012 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imaya/4086371 to your computer and use it in GitHub Desktop.
Save imaya/4086371 to your computer and use it in GitHub Desktop.
zlib.js gunzip demo
<!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