Skip to content

Instantly share code, notes, and snippets.

@ryan-roemer
Created April 20, 2017 08:40
Show Gist options
  • Save ryan-roemer/341e5324a7c2c1dfa1b38cb3cdd15756 to your computer and use it in GitHub Desktop.
Save ryan-roemer/341e5324a7c2c1dfa1b38cb3cdd15756 to your computer and use it in GitHub Desktop.
gzip math fun

GZ Math Fun

$ for f in *.js; do echo $f - $(gzip $f -c | wc -c); done
example.js - 178
without-0.js - 173
without-1.js - 172
without-01.js - 170

We have four nearly identical code blocks at indexes 0, 1, 2, 3.

The experiment:

  • All: 178 bytes
  • Without 0: 173 bytes. Theoretically, 0 is 5 bytes
  • Without 1: 172 bytes. Theoretically, 0 is 6 bytes
  • Without 0 and 1: 170 bytes. Together, the actual removal reduces the total bundle by 8 bytes, which is less than 5 + 6 = 11 individually.
(function(modules) {})
([
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
function(module, exports) {
document.querySelector("#content").innerHTML += foo("different");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("different");
}
]);
(function(modules) {})
([
,
function(module, exports) {
document.querySelector("#content").innerHTML += foo("different");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("different");
}
]);
(function(modules) {})
([
,
,
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("different");
}
]);
(function(modules) {})
([
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
,
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("one");
},
function(module, exports, __webpack_require__) {
document.querySelector("#content").innerHTML += foo("different");
}
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment