Mojo Wonk Blog.

A semi-offical blog dedicated to the Mojolicious web framework

Day 19: You Only Export Twice

Container ship leaving port

With my Yancy documentation site built, with a custom landing page and a POD viewer, I just need to deploy the site. I could deploy the site using hypnotoad, Mojolicious's preforking server with hot deployment, but that would require me to have a server and keep it online. It'd be a lot better if I could just deploy a static website to Github like all the cool people are doing.

But to do that, I'd need to take my dynamic website and turn it into a static one, and that's impossible! Or is it? Why am I asking me, when I'm the one who wrote a way to do it: The Mojolicious export command.

Continue reading Day 19: You Only Export Twice...

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

Too many nuts. I'm gonna need to slim down

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...

Day 15: Practical Web Content Munging

An eyeball of alarming size

Following brian d foy's great write-up of using Mojo::DOM selectors from Day 5, I thought it'd be fun to talk about some website migration scripts I recently built using Mojo::UserAgent and Mojo::DOM, in order to show some basic practical usage of these modules. I've never really used Mojo before, but I recently needed to migrate a website that hasn't had a redesign in about 15 years, and it seemed like a great fit for my content mangling needs. In the past I would have used regexes, and probably would have spent at least as much time manually massaging the input or output into the right shape as I spent writing code. Mojo::DOM made it easy for me, a Mojolicious beginner, to get the results I wanted really quickly.

From Static Site to Static Site Generator

The problem I set out to solve was taking an old static website that was once hosted on SourceForge.net and migrating it to an exciting new...um...static website. But, this time, it'll be a modern take on a static website. Instead of editing HTML by hand and using home-built page munging scripts that would do things like insert news items or changelog entries at the top of the content div using regexes, I'll be using a modern static website generator. There are several to choose from, including the well-known Jekyll, which is written in Ruby, Hugo, built with Go, and Statocles, which is in Perl and runs this site. For my project, I chose Hugo, for its speed and maturity.

Continue reading Day 15: Practical Web Content Munging...