'How to make tomcat server deliver javascript/css from spring boot application on first page load?

I have a small Spring Boot Web Application which is running on a tomcat server. It consists only of a single html page. This page loads some css files in the head-section and two js files at the end of the body.

When I load the page in Chrome (same situation in Firefox etc.) with an empty browser cache the html get loaded correctly but the css/js files get a 404 (see first picture). The result is that the page is completly unstyled and without any functions. When I then hit F5 the page loads completly and looks and works as expected (see picture 2). This behaviour is reproducible! If I ever again load the page without deleting the jsessionid-cookie the page always loads everything.

CSS/JS is not loaded

Page loads completly

The problem seems to be that there is no jsessionid-cookie present in the very first load of the html page. The HTTP-Response to that very first HTTP-request delivers a jsessionid-cookie which the other HTTP-request use (as you can see in the first picture). But the session seems not to be recognized in the servlet.

Every page load later on has a cookie present in the first HTTP-request. Even if the jsessionid-cookie is invalid the page loads completly.

I does not matter if the connection is to localhost or a remote-server, if it's HTTP or HTTPS, if it's HTTP 1.1 or HTTP 2.

Does someone know if this is a configuration problem? Or something special to spring-boot or tomcat?

Ideas appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source