Reputation: 501
Is there any way to hide the version of vaadin version (i.e v=7.6.2) in page source? Also is it possible to change the default directory "VAADIN" to any other directory or rename it?
Upvotes: 2
Views: 433
Reputation: 46
Building on Kuki's answer, this worked for me on Vaadin 8.9.4, no need to copy any js-file.
@Override
public void modifyBootstrapFragment(BootstrapFragmentResponse bootstrapFragmentResponse) {
final List<Node> nodes = bootstrapFragmentResponse.getFragmentNodes();
final String oldVersion = "8.9.4";
final String fakeVersion = "x.y.z";
for (Node node : nodes) {
/* replacing the version in src-attributes */
if (node.attr("src").contains(oldVersion)) {
node.attributes().put("src", node.attr("src").replace(oldVersion, fakeVersion));
}
/* replacing the version in the child-DataNodes */
for (Node child : node.childNodes()) {
if (child instanceof DataNode) {
final DataNode dataNode = ((DataNode) child);
if (dataNode.getWholeData().contains(oldVersion)) {
dataNode.setWholeData(dataNode.getWholeData().replace(oldVersion, fakeVersion));
}
}
}
}
}
Upvotes: 0
Reputation: 4644
Technically speaking it is possible to hide Vaadin version. All you need is to register BootstrapListener
at the start of Servlet session
public class ApplicationBootstrapListener implements BootstrapListener {
@Override
public void modifyBootstrapFragment(BootstrapFragmentResponse response) {
List<Node> nodes = response.getFragmentNodes();
for (Node node : nodes) {
if (node.toString()
.contains("js?v=")) {
String fakeVersion = node.attr("src")
.replace("7.5.8", "1.1.1");
node.attributes()
.put("src", fakeVersion);
}
}
}
@Override
public void modifyBootstrapPage(BootstrapPageResponse response) {
}
}
//somewhere in servletInitialized()
getService().addSessionInitListener(event -> event.getSession()
.addBootstrapListener(
new ApplicationBootstrapListener()));
After this step application should stop working though. That's because Vaadin won't be able to find vaadinBootstrap.js
since you has changed its name. You may need to copy the content of this JavaScript, put it somewhere in the public folder and rename it to whatever fake name you want (in my case it would be vaadinBootstrap.js?v=1.1.1
.
As for the second question, I also think it is impossible, at least without a help of reverse engineering.
Upvotes: 1
Reputation: 2773
I think it is impossible to get rid of VAADIN directory name because it is hardcoded in some framework classes on server and client side. For example: com.vaadin.server.BootstrapHandler, com.vaadin.server.VaadinServlet and com.vaadin.client.ui.ui.UIConnector
Upvotes: 1