I build a site. Under the development mode, it serves .js files nicely. However, under the production mode, the following error occurs:
Refused to execute script from 'http://bowuzhi.herokuapp.com/javascripts/items.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
And the content of http://bowuzhi.herokuapp.com/javascripts/items.js is html:
<div class='page-header'>
<a class="btn btn-primary" href="/zh-TW/items/new"><span class='glyphicon glyphicon-plus'></span>
New
</a><h1>Catalog</h1>
</div>
<div class='row' id='items'>
</div>
<div class='row'>
<div class='col-md-12'>
</div>
</div>
<script src="/javascripts/items.js"></script>
This site is on heroku: http://bowuzhi.herokuapp.com.
Why .js turns out to be html?
I found the answer. The problem is that /javascripts/items.js
was a controller-specified asset. It was included by using the javascript_include_tag
helper on the view instead of included in manifest files (application.js), so it would not be precompiled.
To solve the problem, I added the line config.assets.precompile += %w(items.js)
to my config/application.rb
.
You can find more information in this question: rails-3-1-asset-pipeline-how-to-load-controller-specific-scripts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With