Hi, this is more of a general SPA question. Whenev...
# kvision
k
Hi, this is more of a general SPA question. Whenever I redeploy my kvision app in Google app engine, I get the old app in my browser with javascript errors. In Chrome it loads the new app pages, but the app is not working and threw this error in the console: vf {message: "Invalid parameters", cause: undefined, name: "vf", stack: "vf: Invalid parameters↵ at $T.invoke_508 (https…tps//&lt;my domain&gt;/main.bundle.js25:78621)"} and when I click through, it fails in the last part of this js function function isJsdom() { return ((((!(typeof navigator === 'undefined') ? navigator != null : false) ........ ? navigator.userAgent.match('\\bjsdom\\b') : false; } In Firefox, it loads the old application, still, somewhere it is caching. I have given this index.html <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="0"> I tried clearing the site-specific cache from the browser. PS: In the incognito mode of Chrome and Firefox, no problem at all. Any help, highly appreciated.
r
is your
index.html
file served from /public/ static frontend jar?
you could instead serve it directly from spring boot application as a spring-controlled resource with full access to http cache headers:
Copy code
@Bean
    open fun indexRoute() = coRouter {
        GET("/") {
            ok().contentType(MediaType.TEXT_HTML).cacheControl(CacheControl.noCache().mustRevalidate()).render("index").awaitSingle()
        }
        GET("/index.html") {
            ok().contentType(MediaType.TEXT_HTML).cacheControl(CacheControl.noCache().mustRevalidate()).render("index").awaitSingle()
        }
    }
With template engine defined:
Copy code
@Bean
    fun xmlTemplateResolver(appCtx: ApplicationContext): SpringResourceTemplateResolver {
        val templateResolver = SpringResourceTemplateResolver()
        templateResolver.setApplicationContext(appCtx)
        templateResolver.prefix = "classpath:/templates/"
        templateResolver.suffix = ".html"
        templateResolver.characterEncoding = "UTF-8"
        return templateResolver
    }

    @Bean(name = ["springTemplateEngine"])
    fun templateEngine(appCtx: ApplicationContext): SpringTemplateEngine {
        val templateEngine = SpringTemplateEngine()
        templateEngine.setTemplateResolver(xmlTemplateResolver(appCtx))
        return templateEngine
    }
you can put
index.html
in
src/backendMain/resources/templates
directory
Assuming you are using spring boot on the backend side, of course.
If it still gives you problems with
main.bundle.js
caching you can use this solution: https://stackoverflow.com/a/61096182
k
Great thanks.
t
Hmm... caching greatly improves loading time of the site. If possible I would recommend inserting build-time timestamp / build number / version number instead of current date.
👍 1
r
It's definitely true.
In my opinion the best solution would be to configure webpack to generate bundle file name with hash. https://webpack.js.org/guides/caching/
and to automatically update script directive in the index.html file
But I don't know how to do this 🙂
k
for now I added ?appVersion=20210402.1421. Till I find a way to automate, I will manually set this before deployment.
t
Is your index.html file a template or static file?
k
It is a static file under web/index.html
t
Than I guess the least effort would be to use https://webpack.js.org/plugins/html-webpack-plugin/
k
Will try that.. Cheers