Skip to content

Caching: output hashed assets to dedicated folders #3156

Description

@slorber

🚀 Feature

Currently, the build output looks like:

  • ./build/index.html
  • ./build/docs/myDoc/index.html
  • ./build/someJs.hash.js
  • ./build/someCSS.hash.CSS
  • ./build/someImage.hash.png
  • ./build/someOtherImage.jpeg

Having this flat structure with all file types (hashed or not) melted at the root makes the caching story more complex.

Hashed assets are safe to cache very aggressively, and we should rather move them to a subfolder so that it's easy to enable caching.

For example, aggressive caching can be set by dropping a ./build/_headers config file:

/hashed/*
  cache-control: immutable

It is possible to output the webpack JS files in subfolders:

      filename: isProd ? 'hashed/js/[name].[contenthash:8].js' : '[name].js',
      chunkFilename: isProd
        ? 'hashed/js/[name].[contenthash:8].js'
        : '[name].js',

It should also be possible to achieve with other assets (css, images...).

The files of the /static folder will not be processed by webpack, and not be hashed so they can stay at the root without aggressive caching.

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: intermediateIssues that are medium difficulty level, e.g. moderate refactoring with a clear test plan.featureThis is not a bug or issue with Docusausus, per se. It is a feature request for the future.good first issueIf you are just getting started with Docusaurus, this issue should be a good place to begin.mlhMajor League Hacking Fellowship

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions