Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Spring Boot ignores CSS / JS when loading page

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
My page (order.mustache) uses several CSS styles (external and local), images, background video and JS element. Most of the page layout is described in style.css, which is located in the 'resourses/static/css' directory.

When I start a page through Chrome as an HTML document, it displays correctly. But if I run it through Spring Boot (as a mustache page) - all local styles, images, JS and even youtube videos are ignored.

The browser console indicates an error 'Resource interpreted as Stylesheet but transferred with MIME type text / html:' http: // localhost: 8080 / static / css / style.css'.' On the Response tab of the Chrome developer panel, style.css is displayed as a copy of the order.mustache page. On the Headers tab, its type is text / html.

I can’t understand at what point these changes are happening, and what should I change so that the page works properly.

Honestly, I’m almost sure that it’s either the controller and the get \ post annotations, or the ViewResolver. Perhaps I should specify arguments for GetMapping and PostMapping, instead of using them by default? Or replace them with @RequestMapping (path, method)?




HTML:



Controller:



Main:


 
Sheriff
Posts: 67403
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The resource warning you refer to is just that, a warning.

It's the syntax errors that you should be paying attention to.
 
Andrey Mironov
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:It's the syntax errors that you should be paying attention to.



But I did not find syntax errors in either html or css, and Chrome devmode logs show errors only in .js files. And all refer to one correct line in the temporary "index" file.

Also, if there were errors in the code, would the html page not display correctly in Chome?

 
Andrey Mironov
Greenhorn
Posts: 8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you were right. Changed all href="../static/css/style.css" format links to "/css/style.css" (including .js and .jpeg) - the styles have worked.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic