Created
March 31, 2014 12:33
-
-
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.
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
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