Add timestamps to compiled javascript

249 views Asked by At

I'm using (Ruby-based) Middleman as a front-end site compiler and I want to get build timestamps in my SCSS and JS. I found this solution to add timestamps to SCSS: Add timestamps to compiled sass/scss

Is there an equivalent for JavaScript compiled using Sprockets?

1

There are 1 answers

2
joelparkerhenderson On BEST ANSWER

Yes.

Sprockets provides an ERB engine for preprocessing assets using embedded Ruby code. Append .erb to a CSS or JavaScript asset's filename to enable the ERB engine.

Sprockets processes multiple engine extensions in order from right to left, so you can use multiple engines with a single asset. For example, to have a CoffeeScript asset that is first preprocessed with ERB, use the extension .js.coffee.erb

(The above is from the Sprockets README)

For example, if you have a file hello.js.coffee.erb then you can put this in it:

<%= Time.now.utc.to_s %>