www.ExplorOz.com
Your browser does not support the site menu
Click Here
to load alternative navigation.
Latest News
Road Conditions
Updated 7/08/2008
QLD Coast
Updated 6/08/2008
Kimberley
Western Deserts
SA Deserts
Outback NSW
NSW Coast
Road Conditions
All News...
Site Updates...
Newsletters
Your Name
Email Address
Past Newsletters
Full Index
159
160
161
My Blog - ExplorOz
Click Image to Enlarge
Latest Entry
25th Jul 2008
Total Entries
14
Total Views
3685
 
 
Jump to
Blogs Index
Advertiser
My Profile
|
My Blog
RSS
ExplorOz
Latest Entries
25 Jul 08 - Places: Adding Place Layers (Interactive Place Map)
17 Jun 08 - Members: Trips & Gatherings
12 Jun 08 - Places: Uploading Photos
12 Jun 08 - Places: Understanding Type Attributes
03 Jun 08 - Blogs: Creating Blogs
29 May 08 - Forum: How to change Forum Display Options
22 May 08 - Shop: How do I search the ExplorOz Online Shop?
16 May 08 - PlotSwap: Plot Files Explained
16 May 08 - Treks: How to Submit a Trek Note
15 May 08 - Trader: How do I create a Trader Ad?
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: 423
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
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
HTTP caching and content compression
ExplorOz Mapping Developments
PlotSwap: Plot Files Explained
Members: Trips & Gatherings
Blogs now available to ExplorOz Advertisers
Blogs: Creating Blogs
Forum: How to change Forum Display Options
Places: Create a New Place
Shop: How do I search the ExplorOz Online Shop?
Places: Uploading Photos
New/Updated
SPOT Satellite Messenger $249.00
Navy/White Racer Polo Shirt - TMTE $37.00
Mens Navy/White Polo Shirt - TMTE $31.95
Ladies Navy/White Polo Shirt - TMTE $31.95
Khaki Polo Shirt - TMTE $24.95
Navy Polo Shirt - TMTE $24.95
Garmin Colorado 300 $879.00
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.