Reputation: 790
My understanding toward how Jekyll works is, once I write a blog locally, Jekyll will generate a page and add it to some sort of indexing system, so that when users load up the main page, they can see the list of all the posts. Is that right? However, how does it handle browser caching. Once I add a new post, how can we prevent the browser from using the cached index and make it fetch the new index every time. Or am I saying something totally nonsense?
Upvotes: 6
Views: 3246
Reputation: 2031
There is no "indexing system" involved in Jekyll. It generates pages and associated resources (CSS, JS, images, etc.), that's all.
Caching depends a lot about your HTTP server configuration. HTTP headers sent by the server with any ressource can tell the browser to keep it in its cache for a while, or not at all.
I have these settings in my Apache HTTP server for example:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 year"
# Pages
ExpiresByType text/html "access plus 15 minutes"
# RSS feed
ExpiresByType text/xml "access plus 120 minutes"
</IfModule>
This tells the browsers to keep the ressources in cache for 1 year by default, but HTML pages only for 15 minutes, and RSS feeds for 2 hours. So images, CSS and JS will be cached for one year unless the browser cache needs to free some space.
The delays depends on your writing frequency of course. I am currently migrating a lot of old content, hence the 15 minutes delay, but I usualy publish once a week, so I will set it to 1 or 2 days when the migration is over.
You have to understand that the Expire
HTTP header tells the browser how long to keep the file in cache. Using such configuration, the browser has no way to now there is some new content. There are other ways to deal with caching (like ETag
for example), which allow the browser to ask the server if there is something new, but it is less efficient for web performance.
So if your set the HTML page cache Expire
to 1 day, and the user gets the page just before you update it, she will get the new page almost 1 day later.
This doesn't bother me at all, but you might think otherwise.
HTH
Upvotes: 7