Injecting JavaScript code in autogenerated *.nocache.js file


The Vaadin widget compiler is used to compile custom widgets in Vaadin. The compiler generates code for the custom widget under VAADIN/widgetsets/ directory. Under this directory, there is an autogenerated javascript file ending with “nocache.js”

I need to add my JavaScript function inside this file so that the javascript files loaded after the nocache javascript file can refer to this function.

Which is the best place to incorporate this feature in Vaadin?


It is a bad idea to modify the autogenerated file - your modifications would be lost every time you recompile the widgetset.

What is the real need?

If your javascript needs to be loaded early, one option would be overriding e.g. AbstractApplicationServlet.writeAjaxPageHtmlVaadinScripts(), adding your script on the page before or after calling the superclass method.

That is true and so I could not rely on it.

I am using a third-party JavaScript library which references it’s resources through relative paths but I need to set the base path with respect to the application context. This base path can be set by setting value of a JavaScript variable.

This is exactly what I was looking for.

Thanks for your very quick answer.