Java How to load web page with javascript quicker?

AI Thread Summary
To improve the loading speed of a web page with a large WebGL 3D-rendering JavaScript and a sizable data file, several strategies can be employed. Placing JavaScript file tags at the bottom of the HTML can enhance perceived loading times, although it may slow down the rendering of scripts. Utilizing the "async" attribute can also affect loading behavior, allowing scripts to load without blocking the page rendering. Converting large text data files to binary format could significantly reduce loading times, as binary data is more efficient for the program to process. Implementing these optimizations can lead to a faster and more responsive user experience.
aheight
Messages
318
Reaction score
108
Hi

I have a web page with a 400-line WebGL 3D-rendering javascript which also loads a 45K data file of vertices and other data. It also has a lot of math code. I notice it takes a while to load on slower machines (about 5-7 seconds) as a message on the lower left of the screen reports the % progression of "loading math". Is there a way to load the page quicker? I suppose if I included the data file (of vertices) in the HTML file, that would help. Is that all I can do to make it load quicker?

Thanks for reading
 
Technology news on Phys.org
You can set the page to cache the data locally so that it loads faster next time. However, the user can override that in their browser.
 
Besides optimizing your JS code: put the JS file tag at the bottom of the HTML, compress (minify) the JS, file load from a CDN and make sure it is cachable.
 
Greg Bernhardt said:
Besides optimizing your JS code: put the JS file tag at the bottom of the HTML, compress (minify) the JS, file load from a CDN and make sure it is cachable.

Ok. Thanks for that. I'm very new to HTML/Javascript/WebGL so don't quite understand. I can google and research them.

Can I ask though what do you mean "put the JS file tag at the bottom of the HTML" mean? Do you mean the scripts that load the supporting JS files (including the vertex data)? I have four scripts at the top of the HTML file; one to load MathJax, two load some supporting WebGL functions, and the last is the vertex data:

JavaScript:
<script type="text/javascript" async
  src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML">
<script type="text/javascript"
src="https://dl.dropboxusercontent.com/s/e38perb64eenm6k/glMatrix.js?dl=0"></script>
<script type="text/javascript"
src="https://dl.dropboxusercontent.com/s/7ypkqxyhok5a6fn/webgl-utils.js?dl=0"></script>
<script type="text/javascript"
src="[PLAIN]https://dl.dropboxusercontent.com/s/7w8epbq582lglms/branch1Data.js?dl=0"></script>
[/PLAIN]

So I assume if I put these at the bottom, the page gets loaded quicker? Does the "async" attribute have any effect on the loading?
 
Last edited by a moderator:
aheight said:
So I assume if I put these at the bottom, the page gets loaded quicker?
For best practice yes. Your page will load faster, but the JS will render slower. Does that make sense? In the end this will make a small difference. Measurable, but not always perceivable.
 
Ok thanks for that. I have another question if I may ask: the data file "branch1Data.js" is just a large (45k) text file with string data such as:

var branchVertices=[v1,v2,... vn];
var branchNormals=[n1,n2,...nn];
var vertexIndxes=[i1,i2,...in];

but this is all character (ASCII) data which the program has to then convert to floating point numbers. Wouldn't the process be much quicker if I could just convert all of it to binary and load the binary file or is that not doable?

I ask this because for example this one function actually has 3 branches so that's about 150K of string data and other functions would have even more branches.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
1
Views
911
Replies
4
Views
1K
Replies
8
Views
2K
Replies
13
Views
2K
Replies
2
Views
2K
Replies
8
Views
2K
Replies
3
Views
1K
Replies
23
Views
7K
Back
Top