3

System details:
Server: Apache, Ubuntu 16.02
Client: Windows 10, Chrome

My apache config file looks as follows:

<VirtualHost *:80>
       ServerName mycoolsiteA.mydomain.com
       ServerAlias mycoolsiteB.mydomain.com

       Alias /static /var/www/python/mysite/static
       Alias /templates /var/www/python/mysite/templates

       WSGIDaemonProcess my_app user=www-data group=www-data threads=5
       WSGIScriptAlias / /var/www/python/mysite/start.py
       WSGIScriptReloading On

       <Directory /var/www/python/mysite>
               WSGIProcessGroup my_app
               WSGIApplicationGroup %{GLOBAL}
               order deny,allow
               Allow from all
       </Directory>
</VirtualHost>

When I load the css in a browser it is showing the following. However, this is quite random. It "sometimes" works, and sometimes does not.

My example url is this: https://mycoolsiteA.mydomain.com/static/css/bs/bootstrap.min.css

We do have a Firewall appliance which auto-redirects http to https, but I'm loading the css directly with https.

And the result looks like this: enter image description here

Yet, if I refresh several times, or add a r=number on the end, it will clear the cache and load. But, it will do it again randomly until I clear the cache again.

Here it is loaded and working:

enter image description here

Any thoughts, direction on where to look to fix this?

Machavity
  • 30,841
  • 27
  • 92
  • 100
CodeLikeBeaker
  • 20,682
  • 14
  • 79
  • 108

1 Answers1

8

Welcome to the fun world of UTF-8!

I've seen this dozens of times in PHP (see UTF-8 all the way through). What you're experiencing is almost certainly a UTF-8 file being delivered as some other character encoding (or vice-versa). I downloaded Bootstrap and Notepad++ identifies them as ANSI encoded. Your web server might be forcing that to use UTF-8. Look at the response headers for something like this

Content-Type: text/css; charset=UTF-8

So your web server is saying it's UTF-8 but it's really not. At which point your browser starts vomiting out , meaning it doesn't recognize the character.

There's a couple of ways to deal with this if that's the case.

  1. Re-encode the file as UTF-8 (Notepad++ can do this for you)
  2. Stop passing a default UTF-8. Your browser will try to identify the encoding

Just for kicks, try loading the CSS directly from the MaxCDN servers

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

They do not pass a UTF-8 header

Machavity
  • 30,841
  • 27
  • 92
  • 100