httpremix.com

About the Author

Jonah Ellison lives in Seattle, Washington and works at a web firm developing websites and custom web applications for the LAMP solution stack. He enjoys optimization, front-end usability, databases, clean code and clever solutions. Contact him or learn more.

 

Topics

ArchiveSearch Results

Page Caching for Logged-in Users: Loading Dynamic Content with Ajax 2009 Mar 14

Topics: caching, optimization — by jonah ellison

How fast do your dynamic PHP/MySQL pages load? Answer: probably not fast enough. A truly optimized website should serve pages instantaneously to its visitors. There should be no lag time, even 200 milliseconds of server-side script execution time should be considered a burden worth removing.

The keyword for performance is “caching.” By taking the load off the processor and database, a website can easily handle hundreds of thousands of visitors. Many frameworks offers some sort of caching method that stores the final rendered HTML. This is easy to implement for anonymous users, but what about logged-in users?

I recently released an open-source Drupal module called Authenticated User Page Caching (Authcache) (and a demo site) for logged-in users. Drupal is a great PHP/MySQL CMS/framework for building community-based websites, though it suffers from a “one-more-query” syndrome–a single page request can have hundreds of SQL queries! The reason why authenticated caching is difficult is because most of the time, when you’re logged into a website, the content changes according to your account (like a “You’re logged in as [username]” link), so it’s pointless to save the final HTML to the server’s cache. Instead the entire page has to be rendered by PHP on each request, requiring precious CPU cycles & database hits. Ajax/JavaScript can be used for customizing the cached HTML, however. Of course, this technique can’t be used with every website–some sites are just too dynamic–but it can work if the content of pages is similar across users.


Caching Flowchart

(Read more…)