After a long testing on local server I finally upgraded my production site. At the moment it's NB 2010-12-14. Everything was fine on my desktop but on line things are often different.
The problem is probably due to server caching or something similar but it was not present with the old version of zenphoto (1.2.5_RC2).
Description:
If I display an image page from an album link the image is in its album context.
Then I make a search that give me the same image as a result and I display that image from the search page link. Now the image is still in his album context. To see it in a serch context I need a refresh in browser. The vice versa is absolutely the same.
Is there something I can do, with htaccess for instance, to solve this problem?
The link to my site is in my forum profile.
Comments
They are there, zenphoto_search_params (with the correct search parameters) and zenphoto_last_album, but looking closer it seems that they are not always added and deleted at the proper time.
I'm really lost, any hint about what can be the cause?
Can you check in your browser?
For instance search the word "ricerca" follow the link to the 4th image and then try to display the same image from the album 'fuori catalogo':
http://www.antonioranesi.it/Fuori Catalogo/
I've used firefox, IE8 and opera, same behavior
Zenphoto saves the search context in a cookie. Then when you visit another page it compares the page to see if it is within the search context. If it is, search context is preserved. If not search context is cleared. WEB pages are stateless except for cookies (or sessions) so we really do not know how the link was arrived. We can only make intellegent guesses.
Of course I'm not pretending to open the link I provided from an external page, but from inside the album 'fuori catalogo'.
That's where it's strange if the cookie is not cleared after the album page is served.
But the bottom line is that if you are in a search context and link to an album/image that is present in that context the search context will be preserved as the most reasonable assumption is that you got to the new location from a link on the page that was in the search context.
So the links you have placed on the page that proport to be direct album links will not work as you intend if that album is also part of the search results. Sorry, but that is just the way it works.
If you want to change the behavior you would have to add javascript to those non-search album links that cleared the search cookie.
A thing I don't understand in your explaination is the reason why the cookie is not cleared when you visit the album page. If you are in an album page, called from the menu or from the album thumb link, it means that you are not anymore (or at least that you don't want to be) in search context.
I know that my theme forces a bit the dynamic album behavior, but I made all the tests with the standard zenpage theme and the results are the same. So I still think that the normal zenphoto behavior is more similar to what I expect it to be. I'm sure you don't want that an image clearly called from an album page is then displayed in a search context.
It turned out that there is a caching issue on my remote server.
I don't know exactly what are all the conseguences of what I did, but changing the header directive of image.php and album.php in my theme seems to have solved the problem. The new directive, to prevent apache from caching the pages is:
header("Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0");
Just found this code googling around, my knowlege is too small to understand it all.
So when a page loads it examines the search cookie to see if it (the page) is a within that search. If so it presumes that the search context is still valid.
But of course, caching errors make all bets off:)
My fault was I didn't get that a given album could be between the search results so the cookie could be still needed when in an album page, because I disabled the option to have albums in search results a long time ago.
Please be aware that is not my intention to be polemic in any way. I'm just trying to be helpfull.
I guessed since the beginning that the main problem was a cache problem, as can be seen looking at the title of this topic.
That said I started looking at cookies behavior because you made me notice that the search cookie is actualy NOT being cleared.
That's not true anymore. Once the cache problems have been solved, if I visit an album page the search cookie IS cleared, unless the album itself belongs to search results (I enabled the option to check). That's perfect!
I'll stop arguing on that, instead I'll make more investigation on the header directive and the chache problems.
If this problem is present in my server setup it can affect many other installations of zenphoto. At least the ones mantained by the same hosting company.
The rough solution I used is also preventing the browser to cache pages for its own navigation history.
I have to say again that the efforts of all zenphoto staff to follow and understand all the questions in this forum is really higly appreciated.
Last-Modified: Thu, 23 Dec 2010 06:47:16 GMT
Cache-Control: max-age=172800
Expires: Sat, 25 Dec 2010 06:47:16 GMT
I suppose it means that a browser uses its cached pages for 2 days without ask for a fresh copy, is that so?
As told before I have overrided the cache control, before I knew what it was, adding the header reported a few post above.
That is not a problem for me because my site is mostly a portfolio and I will never have many simultaneous visitors on it.
On the other end Zenphoto can be used by sites with high traffic rate, where a well setted up cache control system can help to have good performances without pay a fortune for web hosting.
Is there something that can be done about it?
Have you never had similar reports from other users?
Should I think that my hosting company is somehow cheating to decrease server load?
I don't think they are "cheating" but maybe a little over optimizing (I am no server expert though). However, you found a way to workaround. But I suggest to talk with them about this issue as well. If they don't know they can't change things. And maybe it even affects others CMS as well.
Do you know if there is a way to let the browser cache at least his internal navigation? I mean, when you use browser's buttons to navigate in history.
Merry Christmas and Happy New Year to you and to everybody around here!
There were still some cache problems with IE8, even with the no cache header reported above, so I decided to disable mod_expires via .htaccess with the following lines:
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
Now everything seems to work better, included a proper behavior of browser's navigation buttons