Joseph
Joseph

Reputation: 7755

How to Cache Busting in Angular Universal

How can i run the command of cache busting in Angular Universal? I tried to run npm run build:ssr --output-hashing=all BUT it doesn't change/add anything.

PACKAGE.json

  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "compile:server": "webpack --config webpack.server.config.js --progress --colors",
    "serve:ssr": "node dist/server",
    "build:ssr": "npm run build:client-and-server-bundles && npm run compile:server",
    "build:client-and-server-bundles": "ng build --prod && ng run sample-project:server:production --bundleDependencies all"
  },

Upvotes: 2

Views: 2921

Answers (1)

Plochie
Plochie

Reputation: 4117

When you are running npm run build:ssr --output-hashing=all, the npm will only execute npm run build:ssr, and will not consider the option provided.

For this add following scripts in package.json and run npm run build:ssr:outhashall

...
"scripts" {
    "build:ssr:outhashall": "npm run build:client-and-server-bundles:outhashall && npm run compile:server",
    "build:client-and-server-bundles:outhashall": "ng build --prod --output-hashing=all && ng run sample-project:server:production --bundleDependencies all"
}
...

Points from comments:

Do note that --output-hashing=all will generate build files with hashed names, so if you have done some changes in project then you will see different file names after each build.

Hence, while deploying application, you need to remove existing files and place new files in deployment folder.

Upvotes: 2

Related Questions