Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Nuxt.js module that uses netlify cache to speed up redeploy process

License

Notifications You must be signed in to change notification settings

DreaMinder/nuxt-netlify-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuxt netlify cache

Nuxt.js module that helps to speed up Netlify content updates by 20%-80%.

⚠️⚠️⚠️ This feature has been implemented as native in Nuxt.js 2.14.0. You might want to upgrade and try it out before using this module, it is much more straightforward. ⚠️⚠️⚠️

Strategies

This package can be used in two ways: Module and Advanced. But generally, the flow looks like this:

  1. Save .nuxt dir to netlify cache dir on a redeploy.
  2. Detect a redeploy that has been triggered with a HTTP-request using netlify hook.
  3. If this request has a special flag inside, restore .nuxt dir from cache and try to use it to speed up the process.

Module usage

This is a simplified approach, but not the fastest one. It uses webpack-cache feature to speed up bundle build process.

  • Add nuxt-netlify-cache dependency
  • Define nuxt module:
{
  modules: [
   'nuxt-netlify-cache'
  ]
}
  • Make sure your generate script includes build command: nuxt build && nuxt export
  • Add a special flag use_cache (flag value changeable with module options) to your netlify-hook like this: https://api.netlify.com/build_hooks/XXXXXXXXXXXXXXX?trigger_title=Your+title+use_cache
  • Add updated netlify-hook URL to your CMS and check netlify deploy-logs to make sure netlify-cache kicked in

Advanced usage

This is a more complicated approach that removes bundle-build process entirely. It saves cache the same way as it does in the module approach, but this time if it detects use_cache flag in redeploy request, it runs nuxt export instead of nuxt build && nuxt export.

  • Add nuxt-netlify-cache dependency
  • Add a new command to package.json
"scripts": {
  "generate:cached": "nuxt-netlify-cache",
  • Change your Netlify Build Command to npm run generate:cached
  • Add a special flag use_cache to your netlify-hook as follows: https://api.netlify.com/build_hooks/XXXXXXXXXXXXXXX?trigger_title=Your+title+use_cache
  • Check netlify deploy-logs to make sure netlify-cache kicked in

Old Nuxt < v2.13

nuxt generate has been renamed to nuxt export in Nuxt.js version >= v2.13. If you are still using old version, you need to use version v0.0.3 of this package.

About

Nuxt.js module that uses netlify cache to speed up redeploy process

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published