Posts

Showing posts with the label gzip

Quick Tip: C# GZip content

A quick post with a simple trick that let us reduce instantly every Ajax interaction over our C#.NET application: [-] public void GZResponse() { if(-1 Response.AddHeader("Content-Encoding", "gzip"); Response.Filter = new System.IO.Compression.GZipStream( Response.Filter, System.IO.Compression.CompressionMode.Compress ); } } The good part is that precedent code, whenever we were using Response.Write, became automatically compatible. Above code could be used to serve JavaScript or css files too: [+] public void GZResponse(){} [-] protected void Page_Load(object sender, EventArgs e) { GZResponse(); Response.AddHeader("Content-Type", "text/javascript"); Response.WriteFile("jquery.min.js"); } That's it :-) P.S. for file serving I suggest a cache system for pre gzipped files

Bases, merits, and defects of packed code

How many times we have seen an included JavaScript apparently incomprehensible? These examples could explain better what I mean: packed.it via MyMin eval((function(M,i,n){return '0("1");'.replace(/\w+/g,function(m){return (n[m]!=i[m]&&i[m])||(i[m]=M[parseInt(m,36)])})})('alert.test'.split('.'),{},Object.prototype)) Dean Edwards packer eval(function(p,a,c,k,e,d){e=function(c){return c};if(!''.replace(/^/,String)){while(c--)d[c]=k[c]||c;k=[(function(e){return d[e]})];e=(function(){return'\w+'});c=1};while(c--)if(k[c])p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c]);return p}('1('0');',2,2,'test|alert'.split('|'),0,{})) These are only two parsers which aim is to reduce code size using an inline decompression technique that is able to evaluate source code after common keywords replacement. Basis of portable and packed code The main goal of these services is to compress a source...