Refused to execute script from [URL] because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled

Created on 20 October 2023, about 1 year ago
Updated 13 February 2024, 9 months ago

Problem/Motivation

I'm getting the below issue after upgrade Drupal 10.1.5

Refused to execute script from 'DOMAIN/session-limit' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
Refused to apply style from 'DOMAIN/session-limit' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

We are seeing this issue only on few pages, e.g /session-limit. If we check the CSS/JS assets in network tab, the files status is set to "307 Temporary Redirect"(Attaching the screenshot).

if we disable Aggregate CSS files/JS files, then everything working as expected.

Can someone please suggest what we can do here

Steps to reproduce

Upgrade Drupal 9.5.8 to 10.1.5
advagg : 6.0.0-alpha1
PHP 8.1.12

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: works as designed

Version

6.0

Component

Compression/Minification

Created by

🇮🇳India gouthamraon

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gouthamraon
  • 🇫🇷France gilbertdelyon

    @gouthamraon
    Same issue on my side.
    The site is 100% private.
    I have a custom module that redirects unauthenticated users to login page.

    It works like a charm when Aggregate CSS is not active
    It doesn't work when Aggregate CSS is active (css is not loaded because wrong mime type, same error as yours)

    Did you find a way in the meantime?

  • 🇫🇷France gilbertdelyon

    I found a way. may be not a good practice but it works!

    First attempt:
    In mymodule/src/EventSubscriber/Mysbsciber.php

    $loginurl = Url::fromRoute('user.login')->toString(); 
    $event->setResponse(new RedirectResponse($loginurl, 301));

    It works only when aggregate CSS is disabled

    Second attempt:
    In mymodule/src/EventSubscriber/Mysbsciber.php

    $loginurl = Url::fromRoute('user.login')->toString(); 
    header('Location: '.$loginurl)
    exit;

    It works only when aggregate CSS is disabled

    Third attempt:
    In mymodule/src/EventSubscriber/Mysbsciber.php

    $loginurl = Url::fromRoute('user.login')->toString(); 
    ?>
    <script type="text/javascript"> window.location.rel="noopener" target="_blank" href= "<?=$loginurl?>";>
    </script>
     <?php

    It works in any case (css aggregate active or inactive)

  • 🇮🇳India Supreetam09 Kolkata

    I don't think this issue is coming from advagg module. We are also facing this issue and trying to figure out whats causing this but we are not using this module. Maybe try to uninstall this module once and check if the issue still persists to confirm if the issue is from this module.

  • 🇫🇷France gilbertdelyon

    Unfortunately I couln't find the reason.
    Our custom module is redirecting anonymous users to login page by way of a controller (based on this example: https://drupal.stackexchange.com/a/223109)
    Redirection works perfectly but style is not loaded when "aggregate css" is selected.

    So we have deleted the controller and now we use a simple hook (https://drupal.stackexchange.com/a/295593) may be not the best practice but now it works!

  • 🇷🇴Romania radubutco

    @gilbertdelyon Probably because you alter also the response for the css request which gets the aggregated files.
    You can try something like this in your EventSubscriber

    if (php_sapi_name() == 'cli' || strpos($event->getRequest()->getRequestUri(), 'sites') !== FALSE) {
      return;
    }
    
  • 🇫🇷France gilbertdelyon

    Thank you, I will try

    BTW: As explained in #6 , since I had this issue I now redirect by way of a hook instead of a controller (and it works!).
    If the suggestion in #7 works, I worry If I should go back to a controller.
    Which wy is the most recommended: hook or controller?

  • 🇫🇷France gilbertdelyon

    @radubutco

    Thank you for your precious help #7. It works!

  • Status changed to Closed: works as designed 9 months ago
  • 🇮🇳India Supreetam09 Kolkata

    In that case, this issue can be closed right?
    Closing this. Reopen if you feel otherwise.

Production build 0.71.5 2024