Crabar
Crabar

Reputation: 1857

Add version to app files with EmberJS

I have next index.html:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1"> {{content-for 'head'}}
  <meta name="fragment" content="!">

  <link rel="icon" href="/assets/favicon.ico">
  <link rel="stylesheet" href="{{rootURL}}assets/vendor.css?{{app-version hideSha=true}}">
  <link rel="stylesheet" href="{{rootURL}}assets/ember-drink-it.css?{{app-version hideSha=true}}"> {{content-for 'head-footer'}}
</head>

<body>
  {{content-for 'body'}}

  <script src="{{rootURL}}assets/vendor.js?{{app-version hideSha=true}}"></script>
  <script src="{{rootURL}}assets/ember-drink-it.js?{{app-version hideSha=true}}"></script>

  {{content-for 'body-footer'}}
</body>

</html>

I want to add version to my css and js file to prevent users load these files from cache when version grows. As you see, I already tried with ember-cli-app-version addon, but it helpers doesn't work in index.html file for some reason.

So how can I add version to my app files?

Upvotes: 1

Views: 182

Answers (1)

ykaragol
ykaragol

Reputation: 6221

You mentioned that I want to add version to my css and js file to prevent users load these files from cache when version grows.

By default, Ember CLI puts an md5 hash at the end of the url of the assets. So that browsers can track the changes. This is called fingerprinting. This is enabled in production builds by default.

To look forward about fingerprinting have a look at this doc.

Further, instead of using md5 hash, if you want to use your versions as a fingerprint; you can customize the fingerprint options. Get value by using the require('git-repo-version') and set the value to the customHash of fingerprint.

But, default configuration is good enough.

Upvotes: 1

Related Questions