Domanda

I'm trying to speed up a Moodle instance (an LMS). I know for certain that users will likely go on their last accessed course, so I'm trying to use link prefetching to download the course page in advance:

<link href='https://moodleexample.io/course/view.php?id=3' rel='prefetch' />
<link href='https://moodleexample.io/course/view.php?id=3' rel='prerender' />

In Chrome, it works rightly. But Firefox shows a strange behaviour. It correctly downloads the web page using prefetch, but when I request the course page, it downloads it again:

Wireshark dump of http requests

You can see from the Wireshark screenshot that it requests the course page again (at time 12.79).

Why does this happen? I tested it on an unencrypted Moodle, and it shows the same unwanted behaviour.

È stato utile?

Soluzione

It was Moodle's "fault". They're dynamic pages, so it puts cache headers that block caching of content.

Using the power of Nginx, I rewrote those headers when getting the X-moz: prefetch from Firefox:

if ($http_x_moz ~ ^prefetch$) {
    more_set_headers 'Cache-Control: private, max-age=60'
    more_clear_headers 'Pragma';
}

In the php location. I have also conditionally inserted the prefetch tag only for firefox, using server side browser detection.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top