Skip to content

Instantly share code, notes, and snippets.

@willbroderick
Created March 31, 2014 12:33
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 willbroderick/9891313 to your computer and use it in GitHub Desktop.
Save willbroderick/9891313 to your computer and use it in GitHub Desktop.
For compressing strings, just a little bit, when you already know good keywords to use for the compression. I use it to trim cookies.
var compList = ['products', 'collections', '_thumb.jpg', '.myshopify.com/', '//cdn.shopify.com/s/files/', 'http://', 'shopify.com'];
function miniComp(str) {
for(var i=0; i<compList.length; i++) {
str = str.split(compList[i]).join('#['+i+']'); //Split/join vs regex speed = surprising
}
return str;
}
function miniDecomp(str) {
for(var i=0; i<compList.length; i++) {
str = str.split('#['+i+']').join(compList[i]);
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment