Prefetch/Preloading of images in the browser

Hi,

To solve the problem with image icons seen rendering the first time i prefetch the
images by executing javascript. To find the image i find the webcontext and add
the path to my theme.

So does anyone know if there are any drawbacks in finding out the webapp context
in the way im doing it? Is there another way to do the thing im doing below.

Below is the code.


        WebApplicationContext webCtx = ((WebApplicationContext)AtlasApplicationUtils.getCurrentApplication().getContext());
        ServletContext sc = webCtx.getHttpSession().getServletContext();
        String contextPath = sc.getContextPath();
      
        this.getWindow().executeJavaScript("(new Image()).src='" + contextPath + "/VAADIN/themes/m2m/../m2m/img/m2m_warning.png';");
        this.getWindow().executeJavaScript("(new Image()).src='" + contextPath + "/VAADIN/themes/m2m/../m2m/img/m2m_warning_serious.png';");

Hi Johannes!

I think you can also use Application.getURL() method and construct the path to resource with it.