CSS MIME type served as text/plain

525 views
Skip to first unread message

Johan Meyer

unread,
Aug 19, 2015, 10:21:43 AM8/19/15
to sparkjava

With static resources I get the following browser error with my css files:
Resource interpreted as Stylesheet but transferred with MIME type text/plain

Im running my service on Tomcat8 so my app is extending Filter and using SparkFilter in web.xml.

No requests for static resources is coming through to my filter so there is no way for me to set the correct mime type.

Any suggestions would be greatly appreciated.

Christian MICHON

unread,
Aug 21, 2015, 1:20:59 AM8/21/15
to sparkjava
Please share the web.xml configuration file.

You need to leave the assets to tomcat. Not to the filter.

Johan Meyer

unread,
Aug 21, 2015, 4:48:17 AM8/21/15
to sparkjava
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>WWW</display-name>
  <filter>
        <filter-name>SparkFilter</filter-name>
        <filter-class>spark.servlet.SparkFilter</filter-class>
        <init-param>
            <param-name>applicationClass</param-name>
            <param-value>www.app.App</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SparkFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>
    <mime-mapping>
        <extension>css</extension>
        <mime-type>text/css</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>js</extension>
        <mime-type>text/javascript</mime-type>
    </mime-mapping>
</web-app>

I decided to rather not use staticFileLocation() and apply my own filter to handle static resources as I need to set different expiration dates for diff resources which Im not able to do with spark.

Martin Paulo

unread,
Aug 23, 2015, 8:58:03 PM8/23/15
to Johan Meyer, sparkjava
I'd be quite interested in a good solution to Johan's problem - as I was trying to solve a similar problem. And my work around feels very hacky :(

Thanks
Martin

--
You received this message because you are subscribed to the Google Groups "sparkjava" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sparkjava+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
=================================================================

Martin Paulo, BSc.
Software Developer


Tel :         +61-3-9434 2508 (Home)
Tel :          04 205 20339      (Mobile)
Site:          http://www.thepaulofamily.net

"Nobody goes there any more. It's too crowded" - Yogi Berra.
Reply all
Reply to author
Forward
0 new messages