www.ExplorOz.com
Your browser does not support the site menu
Click Here
to load alternative navigation.
Latest News
Road Conditions
Updated 2/12/2008
Kimberley
Top End
QLD Coast
Outback NSW
Updated 1/12/2008
WA South Coast
Far North Qld
Road Conditions
All News...
Site Updates...
Newsletters
Not Registered
Register Now
Past Newsletters
Full Index
168
169
170
My Blog - ExplorOz
Click Image to Enlarge
Latest Entry
15th Oct 2008
Total Entries
126
Total Views
14912
 
 
Jump to
Blogs Index
Advertiser
My Profile
|
My Blog
RSS
ExplorOz
Latest Entries
15 Oct 08 - Issues with Internet Explorer 8 Beta (IE8 Beta)
14 Oct 08 - PointPlace & PlotSwap: What program do I use to open .plt and .wpt files?
14 Oct 08 - PointPlace & PlotSwap: When will my PointPlace Credits be available?
14 Oct 08 - Advertising: What are the Terms of Advertising - is there a contract?
14 Oct 08 - Advertising: Where can I view your Site Metrics and Audience Demographics?
14 Oct 08 - Advertising: How much does it cost to Advertise on this site?
14 Oct 08 - Articles: What is the easiest way to find all the Articles?
14 Oct 08 - Shop: Is your shop secure?
14 Oct 08 - Shop: How long will it take to get my order delivered?
14 Oct 08 - Shop: Can I pick up my order and save on postage?
Not Logged on
[Register]
[Logon]
Advertisement
HTTP caching and content compression
Submitted: Monday, Apr 28, 2008 at 15:02
Due to the weight of code that we are now passing between the server and the browser I was getting concerned with the size and speed of the system for our readers. I decided it was time to revisit the caching and compressions system used during content delivery to the browser.
I noticed during debugging using Firebug that the caching of various elements of the system was not 100% and also I was burning user bandwidth with bulky uncompressed js files. So to combat some of this is installed a small compression script in one of my standard system libraries, the code is as below:
Public Shared Sub GZipEncodePage()
If isGZipSupported() Then
Dim AE As String = HttpContext.Current.Request.Headers("Accept-Encoding").ToString
If AE.Contains("gzip") Then
HttpContext.Current.Response.Filter = New System.IO.Compression.GZipStream(HttpContext.Current.Response.Filter, System.IO.Compression.CompressionMode.Compress)
HttpContext.Current.Response.AddHeader("Content-Encoding", "gzip")
Else
HttpContext.Current.Response.Filter = New System.IO.Compression.DeflateStream(HttpContext.Current.Response.Filter, System.IO.Compression.CompressionMode.Compress)
HttpContext.Current.Response.AddHeader("Content-Encoding", "deflate")
End If
End If
End Sub
Public Shared Function isGZipSupported() As Boolean
If IsNothing(HttpContext.Current.Request.Headers("Accept-Encoding")) Then Return False
Dim AE As String = HttpContext.Current.Request.Headers("Accept-Encoding").ToString
If AE.Contains("gzip") Or AE.Contains("deflate") Then Return True
Return False
End Function
Then all I had to do was add a call to GZipEncodePage in the Page.Load event of the various pages of the site I want to compress. I did this on all
trek notes
pages, the trek index and the system home page. This routine cuts the HTML down to around 30% of the original size. Perfect that solves one problem then I moved onto caching.
There is so much information around on the net about this, however it is difficult to sort out the good from the rubbish. I decided to cache all scripts (js include files), and all stylesheets. Due to versioning issues and being able to force the browser to load an updated routine I also need to add the ability to transfer version numbers of these elements. So I used my url rewritting software to create a new rewrite rule and pointed all css and js files to be downloaded via a new program that basically does the following:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim FileName As String = CType(Request("f"), String)
Dim ServerFileName As String = Server.MapPath("/Utilities/Scripts/" & FileName)
Dim MimeType As String = "text/javascript"
If Right(FileName, 3) = "css" Then MimeType = "text/css"
Dim liveStream As IO.FileStream = New IO.FileStream(ServerFileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim buffer As Byte() = New Byte(CInt(liveStream.Length) - 1) {}
If Request.Browser.Type = "IE6" And Right(FileName, 3) = "css" Then
' Do not encrypt IE6 CSS file
Else
Std_Utils.GZipEncodePage()
End If
Response.Clear()
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.Cache.SetExpires(Now.AddYears(10))
Response.Cache.SetMaxAge(New System.TimeSpan(30, 0, 0, 0))
Response.Cache.SetLastModified(System.IO.File.GetLastWriteTime(ServerFileName))
Response.ContentType = MimeType
liveStream.Read(buffer, 0, liveStream.Length)
liveStream.Close()
Response.BinaryWrite(buffer)
Response.End()
End Sub
Simple huh. Well yes after you work out all the little points that cause you to stumble like cache Private vs Public and compressed cache documents. Also the funnies of IE6 and compressed style sheets. Anyway to cut a long story short the above two routines are running live on various elements of the site and showing huge performance improvements in the delivery of content to the browser.
Today I have also instructed the ISP to adjust the caching expiration of the image servers and this will make it even quicker with significant savings in end user bandwidth. This will particularly help the low speed and dial up users that are still out there unable to get decent broadband service.
Tags:
Site Development
,
Work
Views: 662
Comments
Blog Comments are only available to members & advertisers. Why not join now to unlock this and many other features. See Members in the menu.
View Comments (1)
01 May 2008 17:52 - Member - kevin Y (SA)
i noticed an improvement ----- thumbs up
All Entries April 2008
28 Apr 2008 - HTTP caching and content compression
15 Apr 2008 - Blogs now available to ExplorOz Advertisers
24 Apr 2008 - ExplorOz Mapping Developments
Calendar
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
M
T
W
T
F
S
S
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Top Entries
Browser: Firefox Fonts & Windows XP Fonts
HTTP caching and content compression
Treks: How to Submit a Trek Note
ExplorOz Mapping Developments
PlotSwap: Plot Files Explained
ExplorOz Members Support the RFDS
Blogs now available to ExplorOz Advertisers
Members: Trips & Gatherings
Blogs: Creating Blogs
Places: Create a New Place
New/Updated
Mid West WA Explorer Card $20.00
Membership Personal - Lifetime $300.00
South West Map Book $9.95
Frogs and Tadpoles of Australia $19.95
Spiders Snails and Other Minibeasts of Australia $19.95
Dinosaurs and Other Ancient Giants of Australia $19.95
Birds of Australia $19.95
Fast Find
Shop Home Page
Discounted Items
Latest/Updated
All Items
Home
|
About Us
|
FAQ
|
Feedback
|
Site Stats
|
Membership
|
Advertising Campaigns
|
Site Updates
Forum
|
Blogs
|
Forum Archive
|
Trader
|
Shop
|
Treks
|
Places
|
Directory
|
Articles
|
Topics
RSS Feeds
|
Link to Us
|
Terms of Use
|
Corporate Membership
|
Privacy Policy
Copyright © 1999 - 2008,
I.T. Beyond Pty Ltd.
All rights reserved.