General developer forum

 
 
Picture of Joseph Rézeau
Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Hi all,

Upon inspecting moodle sites output Source code, just came across this strange "extra number" inclusion. What's that?

s

Joseph

 
Average of ratings: -
Picture of Simon Story
Re: Strange inclusion of "number" in Moodle URLs
 

It's a unix epoch time. I believe the intention is so when a new theme is deployed a user's browser downloads the right version of resources on subsequent page loads rather than retrieving it from a local cache.

..or it is the government spying on your thoughts!

 
Average of ratings:Useful (1)
Picture of Andrew Nicols
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

Not quite... It is the unix epoch time, but the intention is that the moodle theme serving handlers know that they can safely return a 304 Not Modified without actually looking at or actually serving the file if they are given a request which has either a HTTP_IF_MODIFIED_SINCE or HTTP_IF_NONE_MATCH header.

So the first time a browser requests a file, it doesn't have either of these headers and Moodle will return the file complete with Etag, cache control, and expiration data.

On subsequent visits, a well behaving browser should pass the if modified since header, and moodle just returns the headers and dies without sending the file or having to perform any further checks on the file.

If we didn't have the date of the cache purge then we actually have to compare the if modified since time with the file on disk and determine whether they have changed or not before returning the 304 (or just serve the file each time consuming bandwidth for the poor 2G mobile device).

When the cache is purged, the date is updated and the browser requests the new resource, which it doesn't think it has a copy of, and so it doesn't supply the if modified since header, and moodle actually returns the new file.

So if anything, it's to encourage better browser caching.

Andrew

 
Average of ratings:Useful (6)
Picture of Joseph Rézeau
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Particularly helpful MoodlersGroup TestersGroup Translators

Thanks for the complete, exact answer, Andrew!

Joseph

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

Sorry Andrew, but I think your answer is missing the major point of this.

You are suggesting that this is an optimisation for header checks. In fact that is a red herring. Much more important is that we can safely set an 'Expires' header far far into the future (only a month at the moment, but could potentially be 50 years). This then means the browser doesn't even need to do a http HEAD to ask if a resource has been modified. It simply serves the resource from cache without needing to do any network activity at all.

By using the epoch time in the url, we have the facility to instantly expire this resource. Whilst still having long caching headers.

If it was simply to optimise the header checks then we could deal with this without exposing it in the url. The point of having it in the url is to use the url naming as the mechanism for 'expiring' the resources.

 
Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Dan, if all we wanted to do was to set a long Expires header, then any number would do, e.g. an integer that is incremented by 1 each time.

The reason to use a timestamp, rather than an arbitrary integer, is to optimise the header checks.

(At least, that is my understanding. I may be wrong.)

 
Average of ratings: -
Dan at desk in Moodle HQ, Perth
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Moodle Course Creator Certificate holdersGroup Moodle HQGroup Particularly helpful MoodlersGroup Testers

You are wrong. smile We changed from a counter to an time to prevent problems when people were testing on dev sites (with counter values being reused) - see MDL-33293, or things like the QA site which is continually reset.

In fact, we use that same counter approach with user profile images without the time value.

 
Average of ratings:Useful (1)
Tim at Lone Pine Koala Sanctuary
Re: Strange inclusion of "number" in Moodle URLs
Group DevelopersGroup Documentation writersGroup Particularly helpful Moodlers

Ah. Thanks for explaining.

 
Average of ratings: -