Reputation: 1159
Having a layer of caching for static web pages is a pretty straight forward concept. On the other hand, most dynamically generated web pages in PHP, Python, Ruby, etc. use templates that are static and there's just a small portion of dynamic content. If I have a page that's hit very frequently and that's 99% static, can I still benefit from caching when that 1% of dynamic content is specific to each user that views the page? I feel as though there are two different versions of the same problem.
Content that is static for a user's entire session, such as a static top bar that's shown on each and every page (e.g. top bar on a site like Facebook that may contain a user's picture and name). Can this user specific information be cached locally in Javascript to prevent needing to request this same information for each and every page load?
Pages that are 99% static and that contain 1% of dynamic content that is mostly unique for a given viewer and differs from page to page (e.g. a page that only differs by indicating whether the user 'likes' some of the content on the page via a thumbs up icon. So most of the content is static except for the few 'thumbs up' icons for certain items on the page).
I appreciate any insight into this.
Upvotes: 1
Views: 962
Reputation: 505
You can load the page as a static page and then load the small amount of dynamic content using AJAX. Then you can cache the page for as long as you'd like without problems. If the amount of dynamic content or some other aspect keeps you from doing that, you still have several options to improve performance.
If you're site is hit very frequently (like several times a second) you can cache the entire dynamically generated page for short intervals, such as a minute or thirty seconds. This will give you a tremendous performance improvement and will likely not be noticeable to the user, if reasonable intervals are used.
For further improvements, consider caching database queries and other portions of the application, even if you do so for short intervals.
Upvotes: 4