Professional Documents
Culture Documents
Cache Money
High Performance Websites and Cache Optimization
- Every time a request is made to your servers; code gets executed on the
fly possibly with some database requests. (compiled vs. scripting)
- Caches are used to retain pages or data access over HTTP requests and
reuse them without the expense of re-creating them.
Server:
Sends HTML
File
Joe Client
Server: Reads HTML File
Sends HTML
File
Joe Client
Server: Reads HTML File
Sends HTML
File
lolcat2.jpg
lolcat.jpg
Joe Client
Server: Reads HTML File
Sends HTML
File
lolcat2.jpg
lolcat.jpg
jquery.js
Joe Client
Server: Reads HTML File
Sends HTML
File lolcat.jpg
jumpingWookie.png PirateFail.jpg
Write an automated task or implement a library that takes all .js/.css files
and combines them into one. Various permutations of how this can be
accomplished.
Tip: On code generation grab the mtime (unix) and append it on.
Tip: On code generation grab the mtime (unix) and append it on.
Libraries
- JSMin (http://www.crockford.com/javascript/jsmin.html)
------ C#,Java, Perl, PHP, Python, OCAML, Ruby.
- Packer (http://dean.edwards.name/packer/
----- .NET, PERL, WSH, PHP, APANTA IDE PLUGIN
Libraries
- YUI Compressor (http://developer.yahoo.com/yui/compressor)
------- java -jar yuicompressor-x.y.z.jar myfile.css -o myfile-min.css
Bandwidth Savings:
Reduce the total weight of the file.
24kb x 1 000 000 unique visitors per month= ~22.8GB
Reduce from 24kb to 15kb
15kb x 1 000 000 unique visitors per month = ~14.3GB
http://code.google.com/apis/ajaxlibs/documentation/#AjaxLibraries
You don’t pay for any of the bandwidth being used to download that given
file.
http://www.asp.net/ajaxlibrary/cdn.ashx
Browser
Cache
Problem solved.
"10c24bc-4ab-457e1c1f"
Joe Client Server
"10c24bc-4ab-457e1c1f"
Joe Client Server
- They are typically constructed using attributes that make them unique
to a specific server hosting a site. No good for a large cluster.
Max-Age - Amount of time from when the file was received to when it
expires.
Last-Modified - Compares the modified date in cached to the one in the
server. Just like ETags except using date instead of a custom hash.
Page Caching
- One of the simplest forms of server aching
- Saves generated files .html, .json, .csv to the file system.
- Subsequent requests the server serves up these files directly.
Use when content on entire page doesn’t change very often. This can even be
an entire page that only changes once every hour.
Cache Storage
FileStore - Keeps cached files on file system.
MemoryStore - Keeps cached files in memory. *warning*
DrbStore - Keeps cached files in memory of a seperate, Drb process. Drb ==
Distributed Ruby.
MemCachedStore - Keeps cached files in proven cache server memcached.
Fragment Caching
- When you need more granular control over what parts of the page need
to be cached. Probably because certain parts of the page are unique to the
user.
For example:
Memcached.
- Use CSS. Replace image headers and style when CSS when appropriate.
- Reduce the number of DOM elements on the page. Clean & lean markup.
- Choose <link> over @import for css. (IE will load @import items last)
- Minimize number of iframes
- Where possible avoid unnecessary redirects. Slows down user experience.
- Avoid Empty img src’s <img src=“” alt= “” /> (Safari, Chrome, IE)
- Look into Post-Loading
--- YUI ImageLoader
http://developer.yahoo.com/yslow/
Skype: nathanbertram
Twitter: @nathanbertram
Email: nathan@2012technologies.com
Phone: +1 204 995-3147