3

Has anyone tried creating a process whereby the pages/entries generated from Craft could be presented as static HTML?

I am keen to know what different approaches have been taken in the past as we are considering it for a company website.

5

There are a few different solutions for this. Personally my favourite is to switch on static caching in nginx, as it's a relatively quick and easy solution. Andrew has you covered on how to do that here: https://nystudio107.com/blog/static-caching-with-craft-cms

If you're not using nginx, then a popular choice is the Blitz plugin: https://plugins.craftcms.com/blitz (I've not used it myself so can't really comment, but it sounds good if you're not into rolling your own solution in nginx). Blitz offers a static export of your site too, so it's literally just html files, which would be more portable than nginx's static cache (i.e., you could host the site directly on a CDN).

With any kind of static system, you'll need to ensure:

  1. That any form submissions such as keyword search and contact forms still work by dynamically refreshing any CSRF tokens via AJAX.

  2. That the relevant actions in Craft cause the cache to be deleted. Again, Andrew has you covered here if you're using nginx static caching with the FastCGI Cache Bust plugin: https://github.com/nystudio107/craft-fastcgicachebust

Overall I prefer nginx static caching because I still have the dynamic benefits of a CMS and don't have to worry about complicated workflows for updating an entire load of files and redeploying them somewhere whenever someone corrects a spelling mistake... but I guess if you can fully automate that it's a fine solution.

1
  • Thanks James, this is very helpful! – Andy Lake Nov 26 '20 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.