Repository: getgrav/grav

Issue #2224: CSS and JS files are interpreted as MIME type text/html
Created: 2018-10-15T16:34:05Z
Hello,
I tried to start my Grav Project in my new Fedora 28 environment. Note, the project itself has been run in Linux Mint with Apache and in Digital Ocean Ubuntu 16.04 with Nginx.
Now, I installed NGINX and PHP7 as the backend in Fedora 28. After several days playing around with the configuration of Nginx, PHP, Linux user management and SELinux in Fedora 28. I can start my Grav project on my browser locally, without any permission denied anymore. However, now I can only see the HTML text without the CSS themes and the JS functionality.
The Crome browser console prints these errors:
Refused to apply style from '<URL>' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Refused to execute script from 'http://testsite/system/assets/jquery/jquery-2.x.min.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

My Nginx configuration nginx.conf consists the configuration from the Grav Documentation https://learn.getgrav.org/webservers-hosting/servers/nginx. I replace the mime.types also from https://github.com/h5bp/server-configs-nginx as recommended.
The sites-enabled Nginx configuration in /etc/nginx/sites-enabled/testsite.conf is like this:
server {
    #listen 80;
    index index.html index.php;

    ## Begin - Server Info
    root /var/www/testsite;
    server_name testsite;
    access_log /var/log/nginx/testsite/access.log;
    error_log /var/log/nginx/testsite/error.log;

    ## End - Server Info

    ## Begin - Index
    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }
    ## End - Index

    ## Begin - Security
    # deny all direct access for these folders
    location ~* /(\.git|cache|bin|logs|backup|tests)/.*$ { return 403; }
    # deny running scripts inside core system folders
    location ~* /(system|vendor)/.*\.(txt|xml|md|html|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny running scripts inside user folder
    location ~* /user/.*\.(txt|md|yaml|yml|php|pl|py|cgi|twig|sh|bat)$ { return 403; }
    # deny access to specific files in the root folder
    location ~ /(LICENSE\.txt|composer\.lock|composer\.json|nginx\.conf|web\.config|htaccess\.txt|\.htaccess) { return 403; }
    ## End - Security

    ## Begin - PHP
    location ~ \.php$ {
        # Choose either a socket or TCP/IP address
        fastcgi_pass unix:/run/php-fpm/php-fpm-grav.sock;
        # fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }
    ## End - PHP

}


I've tried several possible solutions from stackoverflow like from https://stackoverflow.com/questions/10075304/nginx-fails-to-load-css-files/23282158. But, no fix for me.
I did include the mime.types in the nginx.conf jsut like in the Grav documentation.
Someone wrote that it happens due to the comment at the beginning of the CSS files.
Any hints to fix this issue?
Thanks in advanced

Duplicate issue #1893: [BUG] js asset added inline doesn't respect order
Created: 2018-02-27T17:58:49Z
Hi there,
It seems that when adding a JS file inline trough param of Grav assets manager, the order is not respected. Inlined assets are always rendered on the last position.
e.g. this:
{% block javascripts %}
  {% do assets.addJs('theme://js/manifest.js, {'priority':100, 'loading':'inline'}) %}
  {% do assets.addJs('theme://js/main.js', {'priority':10}) %}
{% endblock %}
{{ assets.js }}
render into:
<script src="/user/themes/mytheme/js/main.js" type="text/javascript" defer=""></script>
<script>inlined content of manifest.js file</script>
It's a problem that js rendering order doesn't respect the given order in Grav assets manager params as it can break the js code.
Cheers

Closing comment (2021-08-22T23:18:05Z): I've just encountered this error and set up a test for reporting it, then found this. I think it's important the order is respected. I don't think it's an enhancement, rather a bug.
(I guess I can work around this using small assets groups or moving my inline assets to files. I'm making a rough interim port of a terrible WP site, so it's probably a poor setup to start with.)
Since I've gone to the trouble, here are my test steps in case you need them:
Create a stub page at 99.test/assets.md ..
---
title: Test
never_cache_twig: true
---
Here's some content.

Create some asset files in the theme's js directory to output to console. Here's js/test/file1.js, repeat and modify for file2.js and file3.js.
console.log('file 1');
Create a template templates/assets.html.twig in the theme ..
<html>
<head>
<title>Assets test only</title>

{% set inline_js1 %}
console.log('inline 1');
{% endset %}

{% set inline_js2 = "console.log('inline 2');" %}

{% block javascripts %}
	{% do assets.addInlineJs(inline_js1, 100) %}
	{% do assets.addJs('theme://js/test/file1.js', 90) %}
	{% do assets.addJs('theme://js/test/file2.js', 80) %}
	{% do assets.addInlineJs(inline_js2, 70) %}
	{% do assets.addJs('theme://js/test/file3.js', 60) %}
{% endblock %}

{% block assets deferred %}
	{{ assets.css()|raw }}
	{{ assets.js()|raw }}
{% endblock %}

</head>

<body>
{% block content %}
    {{ page.content|raw }}
{% endblock %}
</body>

</html>
My console output was:
file 1
file 2
file 3
inline 1
inline 2

expected:
inline 1
file 1
file 2
inline 2
file 3

Some notes about the template:

I have also tried setting priority with verbose arguments (not shorthand) and also removing priority, which should respect the order
originally my theme folder was called js/tests (with an 's') and for some reason this serves 403 (with content text/plain) as reported in #2224 (but only the assets in that folder). Simply renaming the folder to anything else fixes this (so not permissions). Is there something magic about the name "tests"? I'll report a separate issue if you see one.