In Django I use a background-image stored on a remote web-storage (Digitalocean Spaces) like this:
<style>
.bg-image {
background-image: url("{{ instance.background.url }}");
}
</style>
but the request gets blocked A resource is blocked by OpaqueResponseBlocking
.
The same image is loaded in another place on the same page through a img
tag without problems.
To understand the problem: What is the difference on the server-side requests that the css-url gets blocked while the img-url passes?
2
Answers
The specific problem here is that I used the
<style>
tag to set up the background-image. This - i guess - forced django to send the request withContent-Type: application/xml
that gets blocked.Changing the code to:
fixed the problem.
Opaque response blocking is a new feature waiting to be incorporated into the fetch standard, see https://github.com/whatwg/fetch/pull/1755. Its aim is stated as follows:
Browsers implementing this feature would block images that are served with an XML mime type (for example,
Content-Type: application/xml
), butContent-Type: image/svg+xml
is allowed.