Anand
Anand

Reputation: 51

What is rev-manifest.json file in gulp?

I am new to Gulp. Can anyone explain what is rev-manifest.json file in gulp?

Upvotes: 1

Views: 3528

Answers (1)

Amir
Amir

Reputation: 1905

There are only two hard things in Computer Science: cache invalidation and naming things.

-- Phil Karlton


Gulp has a plugin gulp-rev which is used to append the hash of the file content to the end of its name, so for example script.js would become something like script-134cfcc203.js.

The rev-manifest.json is the mapping that stores the original name and the current name of each file.

This is done for cache invalidation. This is how it's done:

You set the TTL (time to live) of your resources (styles, scripts, etc.) to infinite on your server (nginx, apache or whatever), which means that you're telling your clients' browsers that they should cache the resources forever.

Then when you change the content of a file (e.g. script.js) because you append its hash to its name, then the name would change. Then when the users' browsers request your page, they see it as a whole new file and therefore they're forced to re-download it. But until you don't change the contents of the file, they never re-download it and hence your page's loading speeds up.

Although note that you also need another plugin gulp-rev-rewrite, to search your html files and automatically replace the script.js with its new name, and this plugin uses the rev-manifest.json file to do that.

Hope it is clear enough. Or if it's not, feel free to ask and I will edit and clarify more

Upvotes: 9

Related Questions