Loading resources before running Java code on a servlet

I have a servlet in tomcat. Java code in the backend requires a lot of time. Is there a way to load static resources (css, images, javascript) in parallel with the code in the backend? Right now, they only load after the code completes.

+2
source share
1 answer

You can use an Ajax-style solution in which you draw your page without data, using a placeholder to retrieve the data, possibly even with a loading graphic.

How the Ajax call works, when the page loads, some kind of Javascript is launched, which will launch an Ajax Tomcat request through XmlHttpRequest, which will begin the calculation. The browser will notify the browser when the tomcat request is complete. Then, some javascript will be displayed on the web page, which will accept the response and replace the placeholder. If the server returns an HTML fragment, it is as simple as executing in javascript placeholder-div.innerHtml = text-response-text.

Here's a basic Ajax tutorial and Java example that has a web interface that interacts with the internal Java Servlet server.

+2
source

All Articles