How to load web page with javascript quicker?

  • Context: Java 
  • Thread starter Thread starter aheight
  • Start date Start date
  • Tags Tags
    Javascript Load Web
Click For Summary

Discussion Overview

The discussion revolves around optimizing the loading speed of a web page that utilizes WebGL for 3D rendering and involves a large JavaScript file and a substantial data file. Participants explore various strategies to improve loading times, particularly in the context of slower machines.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant suggests including the data file directly in the HTML to potentially reduce load times.
  • Another participant proposes caching the data locally to improve loading speed for subsequent visits, noting that users can override this setting in their browsers.
  • Several participants recommend optimizing JavaScript code, placing script tags at the bottom of the HTML, compressing (minifying) the JavaScript, loading files from a CDN, and ensuring files are cachable.
  • A participant seeks clarification on the impact of placing script tags at the bottom of the HTML and the effect of the "async" attribute on loading times.
  • There is a discussion about converting a large text data file into binary format to potentially speed up the loading process, with one participant questioning the feasibility of this approach.

Areas of Agreement / Disagreement

Participants generally agree on several optimization strategies, but there is ongoing exploration regarding the best practices for script placement and the potential benefits of using binary data files. The discussion remains unresolved regarding the effectiveness of converting text data to binary.

Contextual Notes

Some participants express uncertainty about the technical details of script loading and the implications of different optimization strategies. There are also assumptions about user behavior regarding caching that are not fully explored.

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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
1K
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 23 ·
Replies
23
Views
8K