.mjs files are not cached by the edge…?


we’ve created a page rule like this a few days ago:

URL: *example.com/static/*
Cache Level: Cache Everything
Edge Cache TTL: a month
Origin Cache Control: deactivated

Our static folder contains some files (css / svg / png) that are successfully cached by Cloudflare in the Edge – except .mjs files. There are no cache headers configured for this folder on the Origin server (NGINX). We have also adjusted the mime type in NGINX for this extension to application/javascript, which is successfully output. Unfortunately, the most important file is not cached by Cloudflare. Is this an error in our configuration?

This is the header response for .mjs files:

Content-Type: application/javascript; charset=utf-8
X-XSS-Protection: 1; mode=block
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=GsKCoHxGZc3L6Ynitg8tJW%2Fy5Z6%2Fudxktr0PeUZNcTYrACcbLmIKYutfhWUZzextmqgA8nNLhjqELxTTHoElMPgRCflZO7nmhsqdzqUQ1zlPNiPcVyrtizMV%2FSP3lQFNTJeNcFJdUC%2FSbviWbKHcNh6P8g%3D%3D"}],"group":"cf-nel","max_age":604800}
Content-Encoding: br
Referrer-Policy: strict-origin-when-cross-origin
Date: Sun, 15 May 2022 07:36:04 GMT
X-Content-Type-Options: nosniff
ETag: W/"6280a555-41cb18"
Last-Modified: Sun, 15 May 2022 07:01:41 GMT
Alt-Svc: h3=":443"; ma=86400, h3-29=":443"; ma=86400
nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
cf-cache-status: DYNAMIC
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
cf-ray: 70ba3355ae26996c-FRA

Thank you for your support.

Would you mind sharing the exact PageRule and exact URL of the file you want to cache?

Sure, this is the current page rule for all subpaths of /static/*:

And there are some files inside this folder:

(The URLs might change in a few hours if there is a new CI build)

Ah, direkt aus der Gegend :slight_smile:

Would you mind trying to change the URL to:

https://schauspielbuehnen.de/static/*” instead of “*schauspielbuehnen.de/static/*”.

Please also check, that no other PageRules that could/would match the given URL, are executed before this PageRule. If you don’t mind, just share ALL of your PageRules (where they are listed) for completeness.


The .css file gets cached, because it gets cached by default. The .mjs does not get cached, because the PageRule:

  1. does not match (not the case)
  2. is not getting applied, because another PageRule gets applied before it

Also please change the content-type/MIME-Type according to the official list to:

Extension Kind of document MIME Type
[…] […] […]
.mjs JavaScript module text/javascript

not to application/javascript

Works now :slight_smile:

Oh… die Welt ist klein :slight_smile:!

Your solution worked! Thank you very much! It gets cached now correctly. There was indeed another page rule before this one just deactivating the auto minification – and thank you for your tip with the mime type. Will also change this according to the suggested type.

Wir haben btw auch ein deutschen Teil im Forum, falls es in Zukunft geschickter auf deutsch ist: Deutsch - Cloudflare Community
Kannst mich da gerne taggen.

You’re welcome!

P.S.: Sonntag ist Ruhetag :smiley:

1 Like

Danke dir, gut zu wissen! :slight_smile:

Das Thema hat mich die Tage nicht ruhen lassen – es musste also heute gelöst werden… :stuck_out_tongue: !

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.