

While sitemaps are not mandatory for great search engine performance, they can facilitate crawling and indexing to bots and hence your content will be picked up faster and rank accordingly. If provided, Google can take additional information from sitemaps into account for search, where appropriate.

Your site has a lot of rich media content (video, images) or is shown in Google News.As a result, Google might not discover your pages if no other sites link to them. Googlebot and other web crawlers navigate the web by following links from one page to another. Your site is new and has few external links to it.If your site pages don't naturally reference each other, you can list them in a sitemap to ensure that Google doesn't overlook some of your pages.
NEXTJS SITEMAP ARCHIVE
NEXTJS SITEMAP INSTALL
Npm install xmlbuilder or yarn add xmlbuilder whichever you prefer. You can setup the sitemap page, have it build on the server, set it and forget it.įirst create the sitemap.js file inside of the pages directory. Thankfully, Next.js can do this inside it's getInitialProps hook and serve up the XML file easily. I also wanted to ditch the extra S3 dependency. There had to be a better way, I wanted to keep my site dynamic with a good cache, and ensure builds only happen for code changes not content changes. It's just more moving parts to worry about. However, as your site gets larger (and maybe handles lots of money), having builds happen at the drop of a hat just makes me uneasy.
NEXTJS SITEMAP FULL
You could do a full rebuild on every webhook event to save the file which, is something many static site evangelists are comfortable with.

The problem with this is that you have to make sure you are saving to the same URL inside S3 and that you still have the same added S3 dependency. I later tried an approach that moved building the sitemap being triggered off of a webhook on every publish event inside of Contentful. Sadly most cloud hosting providers ( Heroku & Vercel) don't allow for adding files after the build is deployed so you now have to save this to a CDN like Amazon S3. My Early ApproachesĪ year ago, I worked out an initial solution that involved using a chron job to create the file regularly. This was one thing that the old monolithic systems like wordpress seemed to have in the bag. "What do you mean Contentful doesn't do sitemaps?!" my SEO colleagues would say-not understanding what headless means fundamentally. Creating a sitemap.xml file was something that always nagged at me when working with headless content management systems.
