colour-science / flask-compress

Compress responses of your Flask application.
MIT License
117 stars 27 forks source link

Add text/javascript mimetype #41

Closed dev-adas closed 1 year ago

dev-adas commented 1 year ago

As of May 2022, MIME type application/javascript has become obsolete in favour of text/javascript. This may explain why one user has reported that their .js files were not being compressed.

The IETF has released RFC 9239 to explain the deprecation. The official list of MIME types posted by the IANA shows that text/javascript is active while application/javascript is obsoleted.

In the backend if Flask is not given a MIME type, it will attempt to guess it. Here is a series of steps that Flask takes to guess the mimetype

  1. The send_file function takes an optional mimetype argument.
  2. send_file calls werkzeug.utils.send_file that will attempt to guess the MIME type by calling mimetypes.guess_type utilizing the cpython mimetypes library
  3. The mimetypes library by default limits to only the official types registered with IANA. The .js file extension in this library maps to text/javascript this is new.

For now users may include app.config['COMPRESS_MIMETYPES'].append('text/javascript') in their app until this PR is merged.

alexprengere commented 1 year ago

Thanks! I just had to fix the tests, otherwise it was spot on :wink: