WP Engineās Atlas is THE headless WordPress hosting platform. In this article, I will discuss and guide you through the easy implementation of the latest feature on Atlas: Support for ISR on Next.js/Faust.js. By the end of this article, you will have a better understanding of ISR and using Atlas to support it with Next.js/Faust.js
Table of Contents
Prerequisites
Before reading this article, you should have the following prerequisites checked off:
- Basic knowledge of Next.js and Faust.js.
- An Atlas account and environment set up.
- Node.js and npm are installed on your local machine.
If you do not and need a basic understanding of Next.js and Faust.js, please visit the docs:
https://faustjs.org/tutorial/get-started-with-faust
Atlas
The all-in-one headless
platform for radically fast sites.
What is ISR?
Incremental Static Regeneration (ISR) is a feature introduced in Next.js that allows you to update static content after it has been deployed. Unlike traditional static site generation, which regenerates all pages at build time, ISR enables you to regenerate individual pages on a timed interval as new requests come in. This ensures that your site remains highly performant while still delivering up-to-date content to your users.
Why Use it in headless WordPress?
In headless WordPress, the front end is decoupled from the WordPress backend, often using Next.js and Faust.js to render the website. This architecture offers several advantages, such as improved performance, enhanced security, and greater flexibility in choosing front-end technologies.
However, one challenge with headless WordPress is ensuring that content changes in WordPress are reflected on the front end without sacrificing performance. This is where ISR becomes crucial. By leveraging ISR, you can achieve the following benefits:
Up-to-date Content: ISR allows your site to fetch the latest content updates from WordPress at specified intervals. For example, by setting a revalidation time of 60 seconds, Next.js will check for content updates every 60 seconds. When a user visits a page, the first user will receive stale content, but subsequent requests will serve the updated content, ensuring minimal delay in content updates.
Enhanced Performance: Since ISR updates only the specific pages that need regeneration at set intervals, your site remains fast and responsive. The initial load times are minimized, and only the changed content is updated, reducing the server load and build times.
SEO Benefits: Static pages are highly favored by search engines due to their speed and reliability. With ISR, you maintain the SEO advantages of static generation while ensuring that your content is always fresh and relevant.
Scalability: ISR enables your site to handle large volumes of content efficiently. Whether you’re running a blog with frequent updates or an e-commerce site with dynamic product listings, ISR ensures that your site scales seamlessly.
All those benefits got me stoked! Letās get it on our Next.js and Faust.js sites!
Configuring Next.js with Atlas ISR Support
Here are the docs link to the Atlas support for ISR.
In your Next.js project, go to your terminal and install the @wpengine/atlas-next package:
npm install --save @wpengine/atlas-next
Code language: CSS (css)
This package provides improved support on Atlas.
Once you install it, ensure it is in your project by navigating to your package.json
file at the root of your project:
"dependencies": {
"@wpengine/atlas-next": "^1.1.0",
"autoprefixer": "10.4.14",
"eslint": "8.44.0",
"eslint-config-next": "13.4.9",
"next": "14.1.2",
"postcss": "8.4.25",
"react": "18.2.0",
"react-dom": "18.2.0",
"tailwindcss": "3.3.2"
}
Code language: JavaScript (javascript)
Now that you have verified the proper installation, staying at the root of your project, modify your next.config.js
file like so:
const { withAtlasConfig } = require("@wpengine/atlas-next");
/** @type {import('next').NextConfig} */
const nextConfig = {
// Your existing Next.js config
};
module.exports = withAtlasConfig(nextConfig);
Code language: PHP (php)
Faust.js Wrapper
If you are using Faust.js, all you need to do is modify your next.config.js
file using the withFaust
wrapper:
const { withFaust } = require("@faustwp/core")
const { withAtlasConfig } = require("@wpengine/atlas-next")
/** @type {import('next').NextConfig} */
const nextConfig = {
// Your existing Next.js config
}
module.exports = withFaust(withAtlasConfig(nextConfig))
Code language: PHP (php)
Next, we need to verify that it works. Run your app in dev mode via npm run dev
and you should see this output in your terminal:
Stoked!!! It works!!!
Atlas User Portal
We now have ISR set up with the proper configuration. The last steps are to connect our remote repository to Atlas, git push any changes, and observe ISR working in all its cache invalidation glory.
If you have not connected your local project to a remote repository, go ahead and do so. Atlas supports GitHub, Bitbucket and GitLab.
Once you have connected your remote repository and added all your necessary environment variables, go ahead and build the app. If you have done this with an existing repo, you can git push
the change, which will trigger a build.
When the application is finished in the build step, you are on the main page of the Atlas portal. Navigate over to the Logs subpage:
In the Logs subpage, click the “Show logs” button on the Runtime option:
You should see the same output focusing on line 6 as you did in your terminal to ensure it’s working properly:
Awesome!!! It is implemented and working in runtime. Now, when you edit or input new content in your WP backend, and then visit the live URL of the Atlas site you just deployed, the ISR should work on the timed interval you set it to like so:
Limitations
Just a note, the docs state that this feature is currently in the Beta phase, which entails:
- Functional completeness, offering comprehensive support for Next.js Incremental Static Regeneration.
- Ongoing assessment by Atlas Platform teams regarding the featureās effect on website performance and application scalability.
Conclusion
Implementing Incremental Static Regeneration (ISR) with Next.js and Faust.js on WP Engineās Atlas platform is a game-changer for maintaining performance and up-to-date content in a headless WordPress setup. By following the steps outlined in this guide, you can leverage ISR to ensure your site remains both fast and current, without the need for full rebuilds.
The integration with Atlas also simplifies the deployment and management process, providing a seamless workflow from development to production.
Get stoked on ISR and Atlas to deliver awesome user experiences and keep your site at the edge of web performance and content freshness. As always, we look forward to hearing your feedback, thoughts, and projects so hit us up in our headless Discord!