Optimize performance for metadata-based integration

Version:

If you're using JSS 22.1 or later and you've integrated your JSS Next.js app with SitecoreAI Pages using metadata, you might have decided you no longer want to integrate with Sitecore Experience Editor. If that's the case, we recommend you make some changes to your app to simplify its configuration and improve its performance.

Important

Metadata-based editing is not currently available in preview mode, so only make these optimizations if you don't intend to use your app as an editing host.

To optimize performance for metadata-based integration:

  1. In the lib/next-config/plugins/cors-header.js plugin, remove the following header (because CORS is now handled by API handlers and middleware):

    {
      source: '/_next/:path*',
      headers: [
        {
          key: 'Access-Control-Allow-Origin',
          value: config.sitecoreApiHost.replace(/\/$/, ''),
        },
      ],
    },
  2. Because there is no further need to enforce absolute URLs, your integration no longer needs to use publicUrl, so we recommend you remove all references to it from your application. Firstly, in layout.tsx:

    1. Remove the following, including the associated code comment:

      // Prefix public assets with a public URL to enable compatibility with Sitecore Experience Editor.
      // If you're not supporting the Experience Editor, you can remove this.
      const publicUrl = config.publicUrl;
    2. Locate the following statement:

      <link rel="icon" href={${publicUrl}/favicon.ico} />
    3. Replace that statement with the following:

      <link rel="icon" href=/favicon.ico`} />
  3. In navigation.tsx:

    1. Remove the following, including the associated code comment:

      // Prefix public assets with a public URL to enable compatibility with Sitecore editors.
      // If you're not supporting Sitecore editors, you can remove this.
      const publicUrl = config.publicUrl;
    2. Locate the following statement:

      <img src={${publicUrl}/sc_logo.svg} alt="Sitecore" />
    3. Replace that statement with the following:

      <img src=/sc_logo.svg alt="Sitecore" />
  4. In lib/config.ts, remove the following:

    publicUrl?: string;
  5. In scripts/config/plugins/fallback.ts, remove the following:

    publicUrl: config.publicUrl || getPublicUrl(),
  6. In next.config.js:

    1. Remove the following, including the associated code comment:

      // Set assetPrefix to our public URL
      assetPrefix: publicUrl,
    2. Then remove the following:

      env: {
        PUBLIC_URL: publicUrl,
      },
  7. If you're connecting Pages to your local instance, update the ServerSideRenderingEngineApplicationUrl setting of the rendering host configuration item in SitecoreAI (/sitecore/system/Settings/Services/Rendering Hosts/Default) to point to the container's external rendering host URL. This URL is typically found in the local container's .env file. Its default value is normally RENDERING_HOST=www.nextjs-starter.localhost.

If you have suggestions for improving this article, let us know!