timmyRS timmyRS - 1 year ago 64
PHP Question

Load a PHP file like it was a JavaScript

I have a

file that I need to load like this

<script src="script.js"></script>

I did instruct the
-file to ignore if
is missing and it's working well, but it doesn't

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

And it wouldn't be a question on SO, if I didn't try to Mime-Type to
. I could load it in using jQuery, but:

  • $.getScript()
    seems to be bugging

  • $.load()
    doesn't fulfill my purpose

Answer Source

As it didn't work in JavaScript, I now have to use this method, which works:

    <?php include "script.js.php"; ?>

This method will however take the user longer to download this page, because caching isn't really possible in-line.

I would still be open for better approaches.