I am using pyramid web framework to build a website. I keep getting this warning in chrome console:
Resource interpreted as Font but transferred with MIME type application/octet-stream: "http:static/images/fonts/font.woff".
How do I get rid of this warning message?
I have configured static files to be served using add_static_view
I can think of a way to do this by adding a subscriber function for responses that checks if the path ends in .woff
and setting the response header to application/x-font-woff
. But it does not look like a clean solution. Is there a way to tell Pyramid to do it through some setting.
Pyramid uses the standard mimetypes
module to guess the mimetype based on the extension. It calls:
mimetypes.guess_type(path, strict=False)
The module looks in the Windows registry if on that platform, and in the following locations for mimetype lists:
knownfiles = [
"/etc/mime.types",
"/etc/httpd/mime.types", # Mac OS X
"/etc/httpd/conf/mime.types", # Apache
"/etc/apache/mime.types", # Apache 1
"/etc/apache2/mime.types", # Apache 2
"/usr/local/etc/httpd/conf/mime.types",
"/usr/local/lib/netscape/mime.types",
"/usr/local/etc/httpd/conf/mime.types", # Apache 1.2
"/usr/local/etc/mime.types", # Apache 1.3
]
You can either extend one of those files, or create your own file and add it to the module using the .init()
function.
The file format is simple, just list the mimetype, then some whitespace, then a space-separated list of extensions:
application/x-font-woff woff
Simply add this following code where your Pyramid web app gets initialized.
import mimetypes
mimetypes.add_type('application/x-font-woff', '.woff')
For instance, I have added it in my webapp.py file, which gets called the first time the server gets hit with a request.
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