How to load web page with javascript quicker?

In summary: Yes, you can load the data in binary form. However, it is faster to load the data in text form first and then convert it to binary.
  • #1
aheight
321
109
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
  • #2
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.
 
  • #3
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.
 
  • #4
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:
  • #5
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.
 
  • #6
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.
 

1. How can I optimize my JavaScript to load web pages faster?

The best way to optimize your JavaScript for faster web page loading is to minimize the amount of code you use. This can be achieved by removing unnecessary libraries, compressing your code, and eliminating any unused variables or functions.

2. Is there a specific method or technique to speed up the loading of JavaScript on my web page?

One effective technique to speed up JavaScript loading is to use a CDN (Content Delivery Network) to host your JavaScript files. This will distribute the files across multiple servers, reducing the loading time for each user.

3. How can I reduce the number of HTTP requests for my JavaScript files?

To reduce the number of HTTP requests, you can concatenate multiple JavaScript files into one, minimizing the number of requests needed. Additionally, you can use asynchronous loading techniques such as using the "defer" attribute, which loads JavaScript after the rest of the page has loaded.

4. Are there any tools or resources available to help me optimize my JavaScript for faster loading?

Yes, there are many tools and resources available to help with JavaScript optimization. Some popular options include Google's PageSpeed Insights, YSlow, and GTmetrix, which can provide insights and suggestions for improving your web page loading speed.

5. Can using a JavaScript framework improve the loading speed of my web page?

Using a JavaScript framework can have both positive and negative effects on web page loading speed. While it can provide a more streamlined and organized approach to coding, it can also add additional weight and increase loading time. It is important to carefully evaluate the necessity of using a framework for your specific web page needs.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
4
Views
739
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
1
Views
480
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
3
Views
951
  • Programming and Computer Science
Replies
23
Views
3K
  • Programming and Computer Science
Replies
5
Views
989
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top