Static Site (11ty) - Outdated pages still online

Hello Guys N Girls

So i’ve got this static site (11ty) that generates Pages based on dynamic data. Now i’ve recognized that when re-deploying (Webhook), some pages still exist that should not. I’ve tried to download the dist folder to check whats going on, but that takes ages “Generating zip” and never finish.

I think it has to do with caching. Is it possible, that it caches html-pages? When running locally an caching, it only caches images (and thats what I want). In the logs i can see all the pages that it generates, so I wonder why there should be old pages still existing…

Thanks for any response :slight_smile:

Hi @MarcFuSa,

Could you share the URLs that you think should not exist?

Hi @hrishikesh

For Example these two:
https://www.fundsachenverkauf.ch/stoeberecke/moebel/garten/60ae63b4ae90724ff6207934/
https://www.fundsachenverkauf.ch/stoeberecke/moebel/kommode-regale-schraenke/6017c89df2b77d3bc42562fa/

Hi @MarcFuSa,

I do not believe this is a cache issue. I can see the file is being generated and deployed in the build:

/stoeberecke/moebel/garten/60c3246b8899358bcff2e106/index.html
/stoeberecke/moebel/garten/603ccdb39cf009775f9271ba/index.html
/stoeberecke/moebel/garten/60ae63b4ae90724ff6207934/index.html <-- one of the file that you linked
/stoeberecke/moebel/garten/610a7f82e6110e436772e014/index.html
/stoeberecke/moebel/garten/61014067452ae034b0cda2da/index.html

That’s a subset of files being generated during build. Are you sure that the dynamic data that you’re using is not having this page at all?

Hmm I’ll check that and get back to you.

Ok so, this data does not exist anymore. So locally, my dist folder is getting bigger and bigger each time I build the site because old html pages still exist. I thought, on netlify a new build will delete the old dist folder and create a new one but uses caching for the images.

I have modified the gatsby caching plugin for netlify so it works with 11ty. Maybe there is something going wrong?

const path = require('path');

const getCacheDirs = (constants) => [
  constants.PUBLISH_DIR,
  path.normalize(`${constants.PUBLISH_DIR}/../.cache`),
];

module.exports = {
  async onPreBuild({ constants, utils }) {
    // print a helpful message if the publish dir is misconfigured
    console.log(constants);
    if (process.cwd() === constants.PUBLISH_DIR) {
      utils.build.failBuild(
        `11ty sites must dist the public directory, but your site’s dist directory is set to “${constants.PUBLISH_DIR}”. Please set your dist directory to your 11ty site’s public directory.`,
      );
    }

    const cacheDirs = getCacheDirs(constants);

    if (await utils.cache.restore(cacheDirs)) {
      console.log('Found a 11ty cache. We’re about to go FAST. ⚡️');
    } else {
      console.log('No 11ty cache found. Building fresh.');
    }
  },
  async onPostBuild({ constants, utils }) {
    const cacheDirs = getCacheDirs(constants);

    if (await utils.cache.save(cacheDirs)) {
      console.log('Stored the 11ty cache to speed up future builds.');
    } else {
      console.log('No 11ty build found.');
    }
  },
};

When I redeploy on netlify when clicking “clear cache and deploy site” then the old pages are gone.

While the code appears to be fine, I can’t say a lot without testing, but as you have already tested, it’s clearly failing somewhere. Maybe the cache is creating problems and restoring the HTML files as they are.

I can’t comment on why this above code is causing problems, but yes, it’s definitely affecting the build pipeline. Maybe there’s another way to cache images?

Hugo, for example, stores the images in resources folder and if configured, it won’t rebuild the images on every build. Maybe 11ty as a similar option somewhere?

Just to understand this correctly on how netlify build things. Am I correct that, the dist folder is NOT persistant and getting rewritten as a whole on every build? Because otherwise I wouldn’t have to cache images since I check every time if this image still exists.

If you commit the dist folder to your repo, it might end up in cache. If it’s not committed and only the build command generates the folder, it won’t go in cache.

I have no dist folder in my github repo. We trigger new builds with a webhook.

So yeah, the folder is not persistent and would be rebuilt from scratch every time you deploy.