Hi all!
I am not able to share the same resource (a png image) in a way it is loaded just once by the client.
Look at this code:
protected void init(VaadinRequest request) {
HorizontalLayout content = new HorizontalLayout();
Resource resource = new FileResource(new File("C:/Temp/image.png"));
Image image1 = new Image(null, resource);
Image image2 = new Image(null, resource);
Image image3 = new Image(null, resource);
content.addComponent(image1);
content.addComponent(image2);
content.addComponent(image3);
setContent(content);
}
When i inspect the html generated in the client browser, i see it loading 3 distinct images from the server:
http://localhost:8080/APP/connector/0/2/source/image.png
http://localhost:8080/APP/connector/0/3/source/image.png
http://localhost:8080/APP/connector/0/4/source/image.png
I have a form (screenshot attached in this post) which shows the same image thousands of times (about 3.000 times).
The image has 1KB, what means the client has to load
3MB
from the server each time it opens the form, when it could load just 1KB…
I realized i can load the same resource just once in the client if i use a ThemeResource or ExternalResource, but my image is loaded from the database (not available from the theme or from an external URL), so i have to use a ConnectorResource (StreamResource).
Is there some way to force Vaadin to send always the same URL to the client for a given Resource, at least for the current form?
Regards,
Fabiano
