Cachtest

Test av en strategi for å hindre at en ressurs (URL) som hentes ved en AJAX-henvendelse caches av nettleseren. Vi sender med en random parameter for at URL'en vi bruker er forskjellig fra gang til gang.

Se kildekoden med javascriptet.
Vi bruker funksjonen uncache for å lage en random parameter som ikke brukes av tjenerskriptet.

function uncache(url){
	return url + '?tull='+Math.random();
}

test HER.

Pythonskriptet ser slik ut:

#! /usr/bin/python
import random
# Simply return a random word from the text below:
text="""Shall I compare thee to a summer's day?
Thou art more lovely and more temperate:
Rough winds do shake the darling buds of May,
And summer's lease hath all too short a date:
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimm'd;
And every fair from fair sometime declines,
By chance, or nature's changing course untrimm'd;
But thy eternal summer shall not fade,
Nor lose possession of that fair thou ow'st,
Nor shall death brag thou wander'st in his shade,
When in eternal lines to time thou grow'st;
So long as men can breathe, or eyes can see,
So long lives this, and this gives life to thee"""

print 'Content-type: text/plain\n'

letters=text.split()
print letters[random.randrange( 0,len(letters)-1)]