How to resolve CSS and JS under Vaadin v14 in productionMode

I am successfully using the following to resolve an image location and put it on a page:

String resolvedImage = VaadinServletService.getCurrent().resolveResource("frontend://img/logo.png", VaadinSession.getCurrent().getBrowser()); Image logo = new Image(resolvedImage, "Logo");

However, this not work for a Stylesheet or for JavaScript files that I would like to load on another page:
String styleSheet = VaadinServletService.getCurrent().resolveResource("frontend://js/v4/style.css", VaadinSession.getCurrent().getBrowser()); String script = VaadinServletService.getCurrent().resolveResource("frontend://js/v4/script.js", VaadinSession.getCurrent().getBrowser());

Strange thing is that the content is correctly resolved in development mode, but not when I run with productionMode=true.

Thanks for your thoughts.

one general question and one is about your specific code/need:

  • "frontend://img/logo.png", "frontend://js/v4/style.css" what actual FS path they refer to ?
  • It’s quite rare situation when you need to use resolveResource in your application. May be there is another way to do what you need. Could you please clarify what you are trying to achieve with the resolved resource String ?

Hi Denis, thank you for your help.

I keep my resources in (the subdirectories of) this folder: [application_name] /src/main/resources/META-INF/resources/frontend/. It is my understanding that this is correct location for Spring Boot-based applications.

In here, I have the following subdirs for static content:
which contain the files you are referring to:
The js/v4 folder contains some more JavaScript files that I use for the D3 example I am working on.

I am not trying to do anything special, on the contrary, I would say. I just want to access/load the content in a way that works both for development and for production mode.

I think you have already created a ticket about this, right ?
Let’s proceed there. The one place is better.