Skip to content

Caching: output hashed assets to dedicated folders #3156

Closed

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.

Activity

  1. added
    feature
    status: needs triage
    difficulty: intermediate
    good first issue
    mlh
    and removed
    status: needs triage
    on Jul 29, 2020
  2. creatorpiyush commented on Jul 30, 2020

    @creatorpiyush

    hi, can I work on this issue?

  3. slorber commented on Jul 30, 2020

    @slorber
    CollaboratorAuthor

    yes thanks

  4. slorber commented on Jul 31, 2020

    @slorber
    CollaboratorAuthor

    @creatorpiyush I just merged this: #3180
    With /assets/images, /assets/media, /assets/files:

    I guess you can do the same and tell webpack to output in /assets/js, /assets/css...

  5. slorber commented on Jan 5, 2021

    @slorber
    CollaboratorAuthor

    closed by #3998

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: intermediatefeaturegood first issuemlh

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions