Tuesday, July 21, 2015

Compressed AJAX Data

String Extension Method Zip:
public static byte[] Zip(this string str)
{
var bytes = Encoding.ASCII.GetBytes(str);
using (var memorystreaminput = new MemoryStream(bytes))
using (var memorystreamoutput = new MemoryStream())
{
using (var gs = new GZipStream(memorystreamoutput, CompressionMode.Compress))
{
memorystreaminput.CopyTo(gs);
}
return memorystreamoutput.ToArray();
}
}

Repository Save:
var showsIQueryable = GetShowsIQueryable();
var serializer = new JavaScriptSerializer { MaxJsonLength = Int32.MaxValue };
var data = serializer.Serialize(showsIQueryable);

var compressedDataBlob = data.Zip();

//stores compressedDataBlob

Controller ActionResult Get:
var showsJsonText = _showService.CommandRepo.GetShowsCache();
Response.Headers.Remove("Content-Encoding");
Response.AppendHeader("Content-Encoding", "gzip");

return new FileContentResult(showsJsonText, "application/javascript");

JavaScript:
$.ajax({
type: "POST",
url: serverUrl,
dataType: 'json',
cache: false,
async: true,
data: JSON.stringify(model),
contentType: "application/json; charset=utf-8"
}).done(function (data) {
....
});

HTML:
<script type="text/javascript">
var shows = @Html.Raw(new JavaScriptSerializer().Serialize(Model.Shows)
</script>

Thursday, July 16, 2015

Friday, July 10, 2015

Watching: Website Performance

























Website Performance
Introduction
Make Performance a Priority
Why web performance?
Performance and user experience
How we get web performance
Focus on the critical path
The total cost of ownership
The Middle-End: YSlow
YSlow rules
Beyond the big 14
The Middle-End: Resources
Images
Minification
The Middle-End: Architecture & Communication
Understanding the middle-end
Introduction to architecture
Data validation
JSON, ajax, & Web sockets
The Front-End: Resource Loading
Preloading images
Lazy loading
Parallel loading
The Front-End: Abstractions & Animation
OO is slower
JavaScript animations
CSS transition vs. css animation
The Front-End: UI Thread, Garbage Collection & jsPerf
The single threaded browser
Threaded JavaScript
Dynamic memory allocation
Introduction jsPerf
JavaScript performance mythbusters