Reduce Yesod compile time

Posted on by

The Yesod devel library already improved a lot during the last years. But still, type safety comes with a drawback sometimes. Since Yesod also secures the static files and how they are included your project, the process can slow down in compile time. Lets say you generate a lot of static assets, JavaScript, CSS and Image files. If you put this files into your static folder (which is the default in Yesod) Yesod will try to create type safe locations for each file. This process is pretty time consuming for our CPU and is not worth it in most cases.

There are two options to get rid of this compile time penalty: Tell Yesod to ignore special subfolder or files Define another folder for generated assets and create another static route

The easiest way is to cover the first option by changing the StaticFiles.hs file in the Settings folder. Usually you will find the entry like this:

staticFiles (appStaticDir compileTimeAppSettings)

We just need to change this to a file list of files we would like to be checked:

staticFilesList (appStaticDir compileTimeAppSettings) [
  , "css/app.css"
  , "css/vendor.css"
  , "js/app.js"

In this case, if there are any other folders with more assets (images, other js or css files), those files will be ignored during the compile time.

I hope this tutorial was helpful to reduce the compile time in Yesod. If you have any questions or comments on this, feel free to use the area below.