开发者

Facebook like mod_rewrite with ajax page loading

This is kind of just a general information question so that I can implement it in a site later, but I was wondering how facebook does their mod_rewr开发者_C百科ite.

To be more explanatory, usually when a site has any kind of ajax page load you see a #/page-name in the address bar. On facebook the url appears just like a normal friendly url. How would you use mod_rewrite to rewrite something like that? or is it something else?


I, too, thought it was mod_rewrite. However, because the pages are loaded asynchronously, there is no invocation of mod_rewrite. I googled, it, came back to SO, and was linked to this, which details the pushState() method, it may help.

https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history

It may not degrade gracefully into browsers not using HTML5, but then again, it might. Let me know how it works for you.


The hash part of a url never reaches your server (I don't think). You catch it with javascript and load the page with ajax. See http://code.google.com/web/ajaxcrawling/docs/getting-started.html for something similar.

http://benalman.com/projects/jquery-hashchange-plugin/ is a simple way to handle it.


PushState alone isn't all that friendly across browsers and versions, so if you want it to degrade nicely you need to do a lot of checking for HTML5 feature support and whatnot. Fortunately, there is a nice package called History JS that handles this very well. Though it provides a plethora of options for tailoring to your needs, you can basically just plug it in and go without worrying too much about compatibility/degrading on various browsers.

https://github.com/browserstate/History.js

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜