Attempts to reduce the size of minified JavaScript by replacing repeated strings with single characters. Latest update reduces output by two characters thanks to a suggestion by @veubeke.
f='GNunescape(encodeURI)^},SM ^/2,Bg=t=u=0,v={};Ky=2,z=M;y<=zy)Kh=0,l ^-y;h<lh)!v[e .substr(h,y)])K=1,f=h;~(f=5,f+y));)++,M=y;Ke @ v)(j=)>1s=G*(j-1)-j-2;s>t||s==tj<u)t=s,u=j,g=e}X=g};Kd=1,F=[];d<127d)e=Str@g.fromCharCode(d),!\']/.test!~5)F.p;F.sort(`a,bNa>b?1:a<b?-1:0}),Z";while((Y=F(B,X))a WX)%Y)+Y+X,Z=Y+Z;q W"\'^<aW\'"\')^?"\'":\'"\',Qfa.\\\\]/g,$&6RegExp(q,"g,"+q)";Ki @ gZe=fWg[i]),f=e%e;f)"},INdocum.getElemById},c.@sertAdjacHTMLbeforebeg@",["JS_cP8#box"De" #ed> Run?\'8button" cr"Dr">\',"Cred_dPdivDi"></div>\']%"<br>)4r6onclick=`V=Ic6,S(V)4d6=Q4i6@nerHTML=V3V to "+Q3Q"4e6#edsetTimeoutQ)",0)}`function(_:" cols99" rows12"D^.lengthW.split(P"></>\'Nreturn Kfor(D id@in8@put type6.5a.@dexOf(e4,I3^+" +G(%.jo@(#checkvalue="replace(textarea.pop())v[e]=`a+q+/[\\r\\neval()+"B)(a);++if((e)"\\\\ushent,\'<){ =a&&")("';for(i in g=' #%34568@DKNPW^_`')e=f.split(g[i]),f=e.join(e.pop());eval(f)
Zj0nRxlOdW5lc2NhcGUoZW5jb2RlVVJJFClefSxTGQtNCV4vMixCGQtnPXQ9dT0wLHY9e307S3k9Mix6PU07eTw9ehN5KUtoPTAsbAleLXk7aDxsE2gpEiF2W2UJLnN1YnN0cihoLHkpXSlLGj0xLGY9aDt+KGY9NSxmK3kpKTspGisrLE09eTtLZSBAIHYpEihqPRopPjELcz1HESooai0xKS1qLTI7EnM+dHx8cz09dAhqPHUpdD1zLHU9aixnPWV9WD1nfTtLZD0xLEY9W107ZD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2YWwoZik=
G = function(i) {
return unescape(encodeURI(i)).length;
}
S = function(C) {
M = C.length / 2;
// Searches the input string for the best possible replacement
B = function(i) {
g = t = u = 0, v = {};
for (y = 2, z = M; y <= z; ++y) {
for (h = 0, l = i.length - y; h < l; ++h) {
if (!v[e = i.substr(h, y)]) {
for (v[e] = 1, f = h; ~(f = i.indexOf(e, f + y)); ) {
v[e]++;
M = y;
}
}
}
}
for (e in v) {
if ( (j = v[e]) > 1) {
s = G(e) * (j - 1) - j - 2;
if (s > t || (s == t && j < u) ) {
t = s;
u = j;
g = e;
}
}
}
X = g;
};
// Get all the characters in the character code range 1-127 that don't appear in str and aren't line breaks
for (d = 1, F = []; d < 127; ++d) {
e = String.fromCharCode(d);
if (!/[\r\n'"\\]/.test(e) && !~C.indexOf(e)) {
F.push(e);
}
}
// Arrange characters so that control characters come last
F.sort(function(i, j) {
return i > j ? 1 : i < j ? -1 : 0;
});
Z = "";
// Replace substrings with single characters while we still have free characters and worthwhile replacements
while ( (Y = F.pop()) && (B(C), X) ) {
C = C.split(X).join(Y) + Y + X;
Z = Y + Z;
}
// Get the most popular type of quote to minimize escaping in the output string
q = C.split("'").length < C.split('"').length ? "'" : '"';
// Create the output
Q = "f=" + q + C.replace(/[\r\n\\]/g, "\\$&").replace(RegExp(q, "g"), "\\" + q) + q + ";for(i in g=" + q + Z + q + ")e=f.split(g[i]),f=e.join(e.pop());eval(f)";
}
I = function(i) {
return document.getElementById(i);
};
c.insertAdjacentHTML("beforebegin", [
'JS:',
'<textarea cols="99" rows="12" id="c"></textarea>',
'<input type="checkbox" id="e" checked> Run?',
'<input type="button" value="crush" id="r">',
'Crushed:',
'<textarea cols="99" rows="12" id="d"></textarea>',
'<div id="i"></div>'
].join("<br>"));
I("r").onclick = function() {
V = I("c").value;
S(V);
I("d").value = Q;
I("i").innerHTML = V.length + " (" + G(V)
+ "B) to " + Q.length + " (" + G(Q) + "B)";
if (I("e").checked) {
setTimeout("eval(Q)", 0);
}
};