@optimizely/cms-hosting
v0.1.0-beta.0
Published
ISR support for Next.js and Astro sites on Optimizely front-end hosting
Readme
@optimizely/cms-hosting
Incremental Static Regeneration (ISR) for Next.js and Astro sites on Optimizely front-end hosting. Pages are served from a cache that every instance shares, and a page refreshes within seconds of an editor publishing it.
- A Redis cache for Next.js (
cacheHandler) and Astro (cache provider) - An Optimizely Graph webhook that is registered when the site starts
- A webhook route that refreshes the published page in the cache and purges it from the CDN
Requires Next.js 16 or later, or Astro 7 or later. The platform supplies every setting.
Installation
npm install @optimizely/cms-hostingNext.js
// cache-handler.mjs
export { default } from '@optimizely/cms-hosting/nextjs/cache-handler';// next.config.ts
const nextConfig = {
cacheHandler: require.resolve('./cache-handler.mjs'),
cacheMaxMemorySize: 0,
// Next.js 16.4 fails to bundle it on Windows
serverExternalPackages: ['@azure/identity'],
};
export default nextConfig;// src/instrumentation.ts
export { register } from '@optimizely/cms-hosting/nextjs';// src/app/hooks/graph/route.ts
export { POST } from '@optimizely/cms-hosting/nextjs/route';Astro
// astro.config.mjs
import { defineConfig } from 'astro/config';
import node from '@astrojs/node';
import { redisCache } from '@optimizely/cms-hosting/astro';
export default defineConfig({
output: 'server',
adapter: node({ mode: 'standalone' }),
cache: { provider: redisCache() },
routeRules: { '/[...slug]': { maxAge: 600, swr: 1800 } },
security: { checkOrigin: false },
});// src/pages/hooks/graph.ts
export { POST } from '@optimizely/cms-hosting/astro/route';{
"scripts": {
"start": "optimizely-hosting register-webhook & node ./dist/server/entry.mjs"
}
}Documentation
- Refresh pages on publish - How it works, setup, limits and troubleshooting
- Deploy to front-end hosting - Put the site live with one command
- Sample - A Next.js site that uses this package
License
Apache-2.0
