Incorrect media type reported for self-hosted CSS, ICO, and XML

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
TomHTML
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Sun Feb 04, 2018 10:19 am

Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by TomHTML » Sun Feb 18, 2018 9:52 pm

The validator is issuing similar complaints about CSS, ICO, and XML files on my own site as it did for the fonts hosted by Google. I've tried to ensure that the right type is being issued via .htaccess directives, but it's to no avail.

Here's what's relevant in my .htaccess file:

Code: Select all

<IfModule mod_mime.c>
	AddType image/jpeg                                  jpeg jpg jpe jif jfif jfi
	AddType image/png                                   png
	AddType image/svg+xml                               svg svgz
	AddType image/webp                                  webp
	AddType image/x-icon                                ico
	AddType text/css                                    css
	AddType text/html                                   html htm
	AddType text/xml                                    xml xsl xsf xsd
</IfModule>
For xml files, the validator complains:
Expected an XML media type like "application/xml" or "text/xml" but got "text/html; charset=utf-8" instead
For CSS files, the validator complains:
Expected a CSS media type like "text/css" but got "text/html; charset=utf-8" instead (link was specified as CSS)
For ICO files, the validator complains:
Expected media type "image/x-icon" but got "text/html; charset=utf-8" instead
Is there a diagnostic I haven't considered I could run to see what's causing the issue? In this case, all the resouces are on my own domain.

Many thanks!

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Mon Feb 19, 2018 1:05 am

Are you able to supply a test file that I can use to reproduce the problem on my end so I can find out exactly why you are seeing these messages?

You can test the media type the server is sending using the 'File->Open from the Web' option and looking for the Content-Type response header. Make sure the server is sending back the correct media/MIME type for the document you are opening.

For example, look for a line like this:

Code: Select all

Response> Content-Type: text/html; charset=UTF-8
If you open a CSS file then there should be a line like this:

Code: Select all

Response> Content-Type: text/css; charset=utf-8
It's also possible that you may need this in your .htaccess file instead (this is what my server uses but yours may be different):
<IfModule mime_module>
...
</IfModule>
Image
Albert Wiersch

TomHTML
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Sun Feb 04, 2018 10:19 am

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by TomHTML » Tue Feb 20, 2018 12:01 am

I've discovered the problem: the validator is relying on the URL for resolving relative paths, even when there is a <base> element with an href indicating where the relative paths are actually to be resolved.

In my case, I have an SPA site where the URL might be:

Code: Select all

https://mysite.com/home/blog-post-1
...and I have a style sheet expressed:

Code: Select all

<link rel=stylesheet href=css/my-styles.css>
...and a base tag:

Code: Select all

<base href=https://mysite.com/>
The style sheet's correctly resolved address is therefore:

Code: Select all

https://mysite.com/css/my-styles.css
But the validator is using the SPA URL (https://mysite.com/home/blog-post-1) for resolving the absolute path of relative resources, so it looks for the style sheet in https://mysite.com/home/, as here:

Code: Select all

https://mysite.com/home/css/my-styles.css
...and therefore returns the "Expected a CSS media type like "text/css" but got "text/html; charset=utf-8" instead (link was specified as CSS)" message, as it's receiving the HTML of the custom 404 page for the site.

I realized this when I saw the ABS url for the resource at the bottom of the window when I selected one of the error messages...I hadn't noticed that before.

I hope this is an easy fix.

Many thanks,
Tom

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Tue Feb 20, 2018 9:19 am

Hi Tom,

Thank you. That is very helpful although I can't seem to reproduce it here. The validator uses the base URL properly when I've tried to reproduce this issue.

For example, when you open the URL in CSS HTML Validator:

Code: Select all

https://www.htmlvalidator.com/test/20180220/blog-post-1.html
and then validate it, the 'Links' tab shows the proper Absolute URLs as computed from the base tag.

Could there be an issue preventing the validator from seeing the base tag?

Are you able to set up a small example on your server that I could access to reproduce the problem?

Also, if you are using any path mappings then please make sure they are correct and not interfering.

Finally, the latest version of CSS HTML Validator Standard 2018 is currently v18.0023. If you are not using that version then you could try re-downloading it and updating, although I can't think of any issues with any 2018 release that might cause this.
Image
Albert Wiersch

TomHTML
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Sun Feb 04, 2018 10:19 am

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by TomHTML » Tue Feb 20, 2018 9:37 am

Hi Albert,

The URL you supplied doesn't validate, with the same problem I encountered. See the attached screen shot. At the bottom of the screen, the link is

Code: Select all

css/my-styles.css
The ABS is

Code: Select all

https://www.htmlvalidator.com/test/20180220/css/mystyles.css
The editor shows the base tag as

Code: Select all

<base href=https://www.hv.com/>
so ABS should have resolved to

Code: Select all

https://www.hv.com/css/mystyles.css
...right?

I'm using version 18.0023, the current version.

What could be causing the problem?

Tom
Attachments
Untitled.jpg
Screen Shot of Validator
Untitled.jpg (169.37 KiB) Viewed 880 times

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Tue Feb 20, 2018 10:32 am

Thank you. That is indeed strange but I was able to reproduce it using the integrated web browser like you were using.

If you go to 'File->Open from the Web' and open the URL there, then validate it, then does the problem still occur?

I am going to investigate why the results are different with the integrated web browser. Thanks for the screen shot! It was very helpful.
Image
Albert Wiersch

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Tue Feb 20, 2018 11:39 am

I found the problem - the base tag was being ignored when using the integrated web browser. This should now be fixed in the next update. It was an easy fix once the problem was found (finding the problem is often the hardest part!).

Thanks again for reporting this and providing the details and screenshot.
Image
Albert Wiersch

TomHTML
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Sun Feb 04, 2018 10:19 am

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by TomHTML » Wed Feb 21, 2018 12:30 am

Great news! I'll look forward to the update.

As for the second method you asked about (File->Open From Web), when I do that, it loads the HTML into the editor (a dialogue window appears first, showing connection info). When I then click on 'Validate', it shows errors in red, even though the ABS path seems reconciled with the BASE tag HREF; see the attached screen-shot. I hope the fix you found for the 'browser' option solves this, too.
Attachments
Untitled2.jpg
File->Open From Web error messages despite correct ABS
Untitled2.jpg (189.48 KiB) Viewed 859 times

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Wed Feb 21, 2018 8:18 am

There shouldn't be a problem there because I made up the "hv.com" domain so it's not surprising those links are bad. The important thing is that the 'Absolute URLs' are correct and based on the "base" tag.
Image
Albert Wiersch

TomHTML
Rank II - Novice
Rank II - Novice
Posts: 28
Joined: Sun Feb 04, 2018 10:19 am

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by TomHTML » Fri Mar 02, 2018 9:38 pm

I've just put the new version through some paces, and it seems to work beautifully! Many thanks!

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3363
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Incorrect media type reported for self-hosted CSS, ICO, and XML

Post by Albert Wiersch » Fri Mar 02, 2018 11:25 pm

Great! Thanks for letting me know. :D
Image
Albert Wiersch

Post Reply