How to append `script` tag in the page `head` tag in Vaadin 23?

I tried the below settings:

public class Application implements AppShellConfigurator {

    @Override
    public void configurePage(AppShellSettings settings) {

    settings.addInlineFromFile(
            TargetElement.HEAD,
            Position.APPEND,
            "frontend/script.html",
            Wrapping.AUTOMATIC);
    } 
    

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

path of script.html file →
src\main\resources\META-INF\resources\frontend\script.html

content of script.html file →

<script async src="https://www.somehost.com/external.js"></script>
<script>
  //some script
</script>

But, I get the error:

Caused by: java.lang.IllegalStateException: Application resource 'frontend/script.html' for inline resource is not available

I want to append the <script> tag inside the <head> tag. What am I doing wrong above?

I assume that the html file is in the wrong place

It should be in /src/main/resource/META-INF/resources

@adaptable-uakari

so, you meant to say that it will not accept any other path inside resources directory?

src/main/resources/META-INF/resources/frontend/script.html ?

Just copied the file to resources and modified the path to:
src/main/resources/META-INF/resources/script.html

but still getting the same error

ah you already have it there sorry. I assume that you have it in the frontend folder in the root directory

I just read the docs. Can you try to put it in the project root frontend folder?

Because it also takes the index.html from there

I placed it there, but I still get the same error :frowning_with_open_mouth:

You could also put the script directly in the index.html

let me try that

yup, that worked :+1:

To make the initial code with frontend/script.html work the file must be in

src/main/resources/frontend/script.html

Vaadin loads these files from the classpath

Pretty confusing

frontend/script.html
I think the above path automatically refers to intended path, but it’s not working for some strange reason. Going ahead with index.html changes for now.

I tried and if it’s in

src/main/resources/frontend/script.html

It works

hmm strange that it isn’t working for me. Kept the file at same location.

indeed. Which version are you using?