Optimize URL for PerformanceMorgan Cheng, Apr 15th 2011@morgancheng
Gawker Outage After Redesignhttp://blogs.wsj.com/digits/2011/02/07/gawker-outage-causing-twitter-stir/
What The Hell?
HashBanghttp://lifehacker.com/#!5785979
Why HashBang?
It All Starts With Desire for Performance
Web 1.0ServerPage APage CPage B
AJAX WebServerOne Page
Fast is Not Enough
Bookmark-able
Hash Fragment is Not Sent to Serverhttp://lifehacker.com/#!5785979http://lifehacker.com/#!3141592Same PageDifferentiated by JavaScript
NavigableBackwardForward
Bonus: AJAX Caching
Looks Hash is enoughWhy Bang?
Audience of Web SiteHuman UserSearch Engine Crawler
Google’s HashBang Schemehttp://code.google.com/web/ajaxcrawling/docs/specification.html
Two URLs for Same Contenthttp://example.com/#!12345http://example.com/?_escaped_fragment_=12345
Only Google officially claims to support HashBang
HashBang makes your content dependent on JavaScript
Don’t Abuse Tech You Cannot Handle
Hey, butFacebook and Twitter do similar trick
So, Red Pill or Blue Pill?
Web Site orWeb Application
HTML5 to Help
HTML5 History APIhistory.pushState(state, newTitle, newUrl)history.replaceState(state, newTitle, newUrl)popstate event
Update URL without HashBanghistory.pushState(null, 	null,     “http://lifehacker.com/314159”)Current Page Doesn’t Refresh
HTML5 History API Detectionfunction supportHTML5History() {	return !!(window.history && history.pushState);}
When can I use HTML5 History?http://caniuse.com/#search=history
YUI History Module
Y.HistoryY.HistoryHashY.HistoryHTML5
Hijax = Hijack + AJAX
Step 1: Build Web 1.0	<a href=“/31415926”>page one</a>	<a href=“/31415927”>page two</a>
Step 2: Add JavaScript	<a href=“/31415926”>page one</a>	<a href=“/31415927”>page two</a>Y.delegate(‘click’, onPageClick, ‘body’, ‘a’);
Step 3: Hijack and Do AJAXfunction onPageClick(ev) {     if (isInternalLink(ev.target.get(‘href’)) {ev.preventDefault();         // do AJAX to update page         // update URL with Hash or History API     }}
More Tricks
http://example.com/12345Navigatehttp://example.com/12345#56789 BookmarkWhat about this?
Flush Inline JavaScript to Redirect<script type=“text/javascript”>    if (window.location.hash) {window.location = directUrl(window.location.hash);    }</script><?php flush(); ?>http://example.com/12345#56789Redirecthttp://example.com/56789
Use Event Delegate
Don’t Over Cache
{http://mustache.github.com/
Graceful Degradation vs.Progressive Enhancement
Thanks

Optimize URL for Performance