Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Problem with rand() and browser cache
Hello,
I’m trying to use rand() to display a link to a random entry, but it seems to get stuck because the browser ‘remembers’ the link and so the randomization stops working.
Here is the structure on my front page:
(article displayed randomly with each visit, and below it a link to a random entry that also changes with each refresh/visit)
<txp:article limit="1" sort="rand()" />
<txp:article_custom limit="1" sort="rand()" form="random" />
And here it is in the archive, what you get once you’ve clicked the random link on the front page:
<txp:article limit="1" />
<txp:article_custom limit="1" sort="rand()" form="random" />
This is where the random link starts to get stuck. In the archives, I don’t want to display articles at random because I want to maintain the section/article/id URL scheme. But I want the link to point to a random article, so that you can navigate at random between archived articles.
One thing I thought of was to find a way of moving the randomization process so that it is executed within the URL, something like <txp:permlink id=“rand()”>Click for random article</txp:permlink> but I don’t know what I would need for this to work?
Btw., here’s what I currently have in the ‘random’ form:
<txp:permlink>Click for random article</txp:permlink>
Thanks,
Helgi
Offline
Re: Problem with rand() and browser cache
In the advanced preferences, try setting Send “Last-Modified” header
to NO.
Offline
Re: Problem with rand() and browser cache
Seems to work now!
Thanks for the help :)
Cheers,
-Helgi
Offline
Re: Problem with rand() and browser cache
helgi, note that turning this option off disables caching for the complete site.
that means, that one random quote made working like this costs you a multiple amount of overall bandwidth from the site in total, which basically means pure cash in the end.
unfortunately i don’t have a handy workaround for you. i am experienced at writing random functions for various display things like random background color et al, nevertheless i don’t know how to use this to display a randomized article selection.
the smartest way to do this would probably be a plugin.
request one on the plugin forum in case you need a workaround for a high traffic site.
Last edited by jayrope (2006-11-09 13:02:34)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: Problem with rand() and browser cache
IIRC, this option was introduced in TXP4.0.4
Didn’t seem to bother a great many people that the pages were sent completely on each request in earlier versions, so unless this is a very high traffic website, I wouldn’t worry about the extra bandwidth used by disabling that option.
Offline
Re: Problem with rand() and browser cache
ruud, sorry my info wasn’t fully researched, nevertheless it always makes sense to minimize web traffic, since that is what costs all internet users bandwidth in the end.
i would consider that as good programmer’s practice (as bad as i am erm with this).
i’d be interested in figures. statistics listing the bandwidth differences of both last-modified on and off options. let’s google…
Last edited by jayrope (2006-11-09 13:50:44)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Re: Problem with rand() and browser cache
That’s highly dependant on the type of site you have and how the visitors behave.
The effect that using last-modified has on bandwidth usage depends on:- how often the content of your pages change and how often people come back to check if anything has changed. If the page changes more often than people come back to check for changes, then using last-modified doesn’t help.
- the amount of TXP generated content versus the amount of static files (images, files, etc). If the total bandwidth used by text is minimal compared to the bandwidth used on images, using last-modified has only a minor effect on total bandwidth.
- browser cache settings. Some have it set to never cache at all (sometimes that is a company policy).
On my own website (300MB/month in traffic) I save around 15% due to last-modified, but that’s mostly on images which consume 90% of bandwidth.
On another website where I could check statistics and which serves mainly static text (50% images), savings were around 25%.
And on the last site I checked (8GB traffic), savings due to last-modified were 35%. This happened to be the only site that was using TXP (4.0.3), so all those savings were due to images being cached. Images are 77% of all bandwidth used, so the remainder (23%) is due to Textpattern. Even if I’d upgrade to 4.0.4 and enable the last-modified option, the effect would minimal on total bandwidth usage, because it’s a website that has daily updates (on average).
Last edited by ruud (2006-11-09 15:08:42)
Offline
Re: Problem with rand() and browser cache
thanx much ruud, that’s quite helpful figures. i am personally running a site with .mp3 downloads (currently switched off) which allows up to 250GB bandwidth per month, caching woulnd’t help on such media files.
generally still i believe, that it makes sense to free the already overflown net from any kind of superflous traffic, therefore i would switch on caching whenever possible and rather write a workaround for special cases like the original issue of this thread.
Last edited by jayrope (2006-11-10 17:18:40)
A hole turned upside down is a dome, when there’s also gravity.
Offline
Pages: 1