简体   繁体   中英

Spring Boot and html not rendering javascript

I am trying to cache some results of a js script. (note this is working for other things like raw string data returned from a service, just not for this. Also note this is the first time I am trying to do it with a script and.js file.

Working: in html:

<script src="https://www.notmydomain.com/script.js?param1=blah"></script>

not working: in html:

<script src="/script.js?param1=blah"></script>

in @RestConroller method (from System.out.println's I know its returning the exact same thing as when I call the script directly):

    @GetMapping("/script.js") 
    public String script(Model model, @RequestParam Map<String,String> allRequestParams) {
        String parameters = inputParameterBuilder.buildParametersString(allRequestParams);

        String js = pagesCacheService.getPage("script.js"+parameters, null, String.class);
        if(null == js) {
            js = resttemplate.getForObject("https://www.notmydomain.com/script.js" + parameters, String.class);
            pagesCacheService.updatePage("script.js"+parameters, js, String.class);
        }

        return js;
    }

Thanks, Brian

Solved the issue: @GetMapping(value = "/script.js",produces = "text/javascript")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM