You've just read How to lose Weight in the Browser and you want to know to slim down your Mojo app. Part of that process is preventing the browser from requesting files that hardly change. I spent a well-caffeinated afternoon trying to do that with Mojolicious. I've been 'round the houses, and spoiler alert I didn't find the answer until the very end, kind of like your favourite Christmas animated special with a small woodland creature narrating "The Gruffalo's HTTP header".

A Children's Story

Our beloved small woodland creature needed to display a web calendar with forest events pulled from a database. Perl could get the event data and package it as a JSON feed. Mojolicious could prepare the webpages with the correct JSON feed for each user. With some JavaScript libraries to display the web calendar, all would be well in the forest.

Everything except the JavaScript libraries are lightweight. And everyone knows a page reload goes so much faster if it doesn't have to download the JavaScript every time. Those libraries won't change for months! If only the client browser knew that it could use the file that it had downloaded last time.

The secret, of course, is to set the Cache-Control field of the HTTP header, but how?

Continue reading Day 16: A pre-Christmas Diet for Mojolicious - A Children's Story...