Refused to apply style from 'url' because it's MIME type ('text / html')

1

I have the following problem loading the assets in a site that I have uploaded to 000webhost

  

Refused to apply style from   ' link '   because its MIME type ('text / html') is not a supported stylesheet MIME   type, and strict MIME checking is enabled.

This is the site: link

The fact is that this is PHP's own framework, I generate the urls of assets in the following way;

<link href="<?= Assets::setAssets('css/ligne.css') ?>" rel="stylesheet" type="text/css">
<link href="<?= Assets::setAssets('css/font-awesome.css') ?>" rel="stylesheet" type="text/css">

This returns me the following;

<link href="https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/ligne.css" rel="stylesheet" type="text/css">
<link href="https://ucrmreportcustom.000webhostapp.com/ucrm_client_report/webassets/css/font-awesome.css" rel="stylesheet" type="text/css">

Assets::setAssets

/**
 * Recibe un string con el elemento que se pretende agregar al proyecto
 *      eje: 'css/main.css'
 *      eje: 'js/jquery.min.js'
 * Este retorna una url absoluta
 * Tiene parametro opcional para determinar si se permitida que el navegador
 * almacene la cache de los assets
 *
 * @param $asset
 * @param bool $cache
 * @return string
 */
static public function setAssets($asset,$cache = true)
{
    $domain = $_SERVER['SERVER_NAME'];
    $assets_dir = 'webassets';
    return PROTOCOL . '://' . $domain . '/' . self::root_dir() . '/' . $assets_dir . '/' . $asset . self::cache($cache);
}

/**
 * Retorna el nombre de la carpeta base del proyecto
 * esto es relativo ya que la carpeta donde esta el framework podria
 * llamarse de cualquier manera y con esto se obtiene este nombre para
 * hacer referencia a los assets
 *
 * @return string
 */
static private function root_dir(){
    $root_dir = $_SERVER['REQUEST_URI'];
    $root_dir = explode('/',$root_dir);
    return $root_dir[1];
}

/**
 * Se utiliza para retornar el tiempo a la url de los assets para
 * evitar que el navegador almacene estos en cache
 *
 * @param $bool
 * @return string
 */
static private function cache($bool){
    if(!$bool){
        return '?' . time();
    }
}

I have tried the following without success;

  • Add <base href="/"> before all assets
  • Place the absolute URL
  • Move files to another directory
  • Change the mime type to text/html

My last letter is to ask the community.

Edit:

In local this works perfect, I can even access the assets through the url;

http://localhost/ucrm_client_report/webassets/css/ligne.css

    
asked by Albert Hidalgo 20.11.2018 в 15:22
source

2 answers

0

I have already solved it, the problem is that the server is case sensitive;

The webassets folder I have with the uppercase W on the server.

    
answered by 20.11.2018 / 17:25
source
0

If you open your page with the console you will see that the CSS and JS do not load. None. They give error 404 and the server sends a small HTML page informing of the error, with which the MIME type is set to text/html .

Try loading this link and you will see that it does not work:

link

    
answered by 20.11.2018 в 15:48