onlinespending
onlinespending

Reputation: 1159

Caching dynamic web pages (page may be 99% static but contain some dynamic content)

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.

I appreciate any insight into this.

Upvotes: 1

Views: 962

Answers (1)

Brian H.
Brian H.

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

Related Questions