JavaScript files are being served as text/plain in App Engine, regardless of what I do to change that:
'content-type' header media type value should be 'text/javascript', not 'text/plain'.
Anyone have any insight into what I'm doing wrong and how to get these to show up as the appropriate type?
I have three .js files in a 'static' subdirectory off of the main project. I've tried a few different ways to configure this, but nothing seems to work.
app.yaml:
- url: /(.*\.js)
static_files: static/\1
upload: static/.*\.js
mime_type: text/javascript
I tried specifying them individually. (for static/script.js:)
- url: /static/script\.js
static_files: static/script.js
upload: static/script\.js
mime_type: text/javascript
also
- url: /static/store.js
static_files: static/store.js
upload: static/store.js
mime_type: application/javascript
I've also tried setting it in the html:
<script src="{{ url_for('static', filename='script.js') }}" type="text/javascript" charset="UTF-8"></script>
Everything works, but I'm getting errors about the javascript files being the wrong MIME type on every page, as well as "Response should include 'x-content-type-options' header." for every file accessed by each page.
I finally was able to remove most of the x-content-type-options errors by adding 'http_headers' as below, but then all scripts from the .js files are refused because they're not registering as the correct MIME type.
handlers:
- url: /static
static_dir: static
http_headers:
X-Content-Type-Options: nosniff
Thanks in advance for any insights you can provide!
*Update
Flask mime type configuration:
app = Flask(__name__, static_url_path='/static')
app.config['MIME_TYPES'] = {
'.js': 'text/javascript'
}
If you didn't use
dev_appserver.pywhen testing locally, then you didn't actually test the contents ofapp.yamlfile which might be why it worked locallyFor python, all you need in your
app.yamlfile is something like thisNote that the value of
static_dirdepends on the location/path of thestaticfolder with respect to your project root folder