We have a site deployed in production with xyz webmasters. Below are two screenshots of the web console when the error occurs in two different instances.
We are facing this issue intermittently and not consistently. Moreover, this is occurring with few users and not all the users (i don't know if this is related to region or not). When this issue occurs, the page does not load properly. After few refresh attempts, the page loads properly and everything else works as expected.
It is known fact that webmasters enabled strict MIME type checking.
The URL paths of all the resources (.js & .css files) are accurate. The MIME type set at origin for these files is correct. Below is the code snippet of the .jsp page where these files are referred.
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/css/jquery/jquery-ui.css" type="text/css" />
<script src="${pageContext.request.contextPath}/static/js/jquery/jquery.min.js" type="text/javascript" ></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap/bootstrap.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery/jquery.slimscroll.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery/jquery.dataTables.min.js" type="text/javascript"> </script>
As per my understanding, the request flow works like in this small diagram.
I suspect that the issue is caused by webmasters servers when they are sending response back to client browser (step 4). After they read response from App server, I suspect their server is failing to maintain the same Content-Type of the file (.css/.js). Before I claim this, I want to confirm my understanding but I am falling short of tools to prove this as it is happening only in production. We don't see this issue in our development environment to debug!!!
As per webmasters, the issue is in application's code. What I can see in our code is the type for each .js / .css files in .jsp file. What I see is that the browser is NOT accepting the response from webmasters. As we are maintaining rel="stylesheet" type="text/css" for CSS files and type="text/javascript" for all javascript files, I don't see the issue in application server!!
Thanks in advance for your advises.
Edit 1: Added mimetypes in web.xml, as below:
<mime-mapping> <extension>js</extension> <mime-type>application/javascript</mime-type> </mime-mapping> <mime-mapping> <extension>css</extension> <mime-type>text/css</mime-type> </mime-mapping>
Added mimetypes to server.xml in liberty server, as below for reference.
<mimeTypes>
<type>js=application/javascript</type>
<type>css=text/css</type>
</mimeTypes>
Inspite of this the we often get mime type mismatch in the browser. The webmasters team claims that application server must be sending wrong content, without any reasonable information.
Edit 2: Then I tested what are the headers the resources (js/css files) are sending with below command.
curl -I https://myapplication/static/js/angular/angular.min.js Below is the response I get. It is consistently returned the same response when I run the loop 100 times.
HTTP/1.1 200 OK X-Backside-Transport: OK OK Content-Language: en-US Content-Length: 168517 **Content-Type: application/javascript** Date: Tue, 19 Jun 2018 10:38:25 GMT Last-Modified: Tue, 29 May 2018 17:04:10 GMT X-Powered-By: Servlet/3.1 X-Global-Transaction-ID: 1178221711 Connection: close
So, I don't see any issue on application server side.
- Edit 3: When webmasters suggested that a stale cache may create this kind of issues, the cache is disabled from their side. I additionally written server side code to ensure that cache is disabled. Below is the code snippet for reference:
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setHeader("Expires", "0"); // Proxies.
To make sure that the resource is loaded from server and not from cache, look at the network tab in developer tools. If the resource indicates 200 status code, it is loaded from server successfully. If the status code is 304, it is loaded from cache.
- Edit 4: I have no knowledge how the webmasters establish ssl connection. When a SSL connection is not established properly, it gives the content as text/html. At this stage, I don't know if that is the case. I am looking for all possible areas to solve the issue!!!