Welcome Guest, Not a member yet? Register   Sign In
Possible to cache two versions of a page?
#1

[eluser]DisgruntledGoat[/eluser]
I'm using CI's caching tools. On several pages, I decided to remove a bunch of images (they were CSS-sprited but still over 300K in size) and let the user decide if they wanted to show them, via Javascript.

Then I thought it would be neat to allow the user to keep images displayed across the various pages to avoid repeated clicking of "display images" (and especially since the images would be cached in their browser once loaded). So now it's an option of "images off" (default) or "images on".

I'm using a cookie to store the user preference, but this means I can't serve a cached version of the page because it will be different for half the visitors. Can I cache two versions of the file, and serve a different one based if the cookie is present?

I am currently using a Javascript solution that checks for the cookie via JS and loads images. But I'm hoping for a server-side solution if possible.
#2

[eluser]DisgruntledGoat[/eluser]
Anyone have any ideas? Can you manually add something to the cache, eg as a different URL?
#3

[eluser]c77m[/eluser]
Great question, as this is something that will be crucial for me in the near future...

The User Guide states caching can be enabled on a per-page basis, but I'm not sure exactly how a "page" is defined in CI lingo.

Check out the application flow chart (here: http://ellislab.com/codeigniter/user-gui...pflow.html), and in step 3 we see the routing determines whether or not a cache exists. I'm going to have to get a bit more in the weeds with this to see how it works, because it almost looks like it would be per-URI without regard to security. (I can't imagine that's accurate, but that's how it looks.)




Theme © iAndrew 2016 - Forum software by © MyBB