To prevent the display speed decreases in external JavaScript and CSS external

It – Hardware & Software | | 7 views

How you write separate them when using the CSS or JavaScript in Web pages, files and call from HTML is often used. Independent if JavaScript and CSS that are common to multiple pages in a single file and should be easy to maintain, ( for files once loaded are cached by the browser, given in the entire website ) shorter reading speed.

Description and position affect the speed

But might it let slow Web page loading speed and speed depending on the position and how to write the source to load the external file.

So we introduce load external files by the terms speed becomes slow and how to avoid it.


How to load external CSS files two variances

calling the CSS “@ import”

If you want to read more than one CSS file, two types of writing is. One is a way of describing the “@ import” and at the beginning of the CSS source.

For example, after see 2.css”two external CSS file f.e.”1.css”and the following at the beginning of the”1.css”source when loading the”1.css”also see 2.css” loaded. @ import url (“2.css”);

load all the link elements in

How to read 1.css and 2.css put one link element from scratch in the HTML head element that can.

For example after you write HTML, see 2.css”2 file loads and”1.css”.
“2.css < link rel =”stylesheet”type =”text/CSS”href =”1.css”/ >< link rel =”stylesheet”type =”text/CSS”href =” / >
Neither the results the same, will load 2 CSS files can. But the difference goes to the load speed.

How to write, time to read complete different

Below is a chart that displays the elapsed time to display the Web page read each file. The example to page loading external CSS four files from one HTML file.

  • CASE 1 (upper) if one after another called the CSS file using the “@ import”
  • CASE 2 (lower) if called at least four using the link element in HTML

If you read the four CSS files from HTML takes time graph

As for easier loading of each CSS file takes at least 5 seconds to download has adjusted. Blue is actually downloading time, waiting for response from the server (yellow and green) and other such.

Obviously, long time on display better using “@ import” ( CASE1 ) . Not read only 1 file at a time is because though it is the ability to load multiple files at the same time (to download),.

Whether required files found when reading HTML

the load target in the “@ import”

Slow if??
is a way to use “@ import”, until you read the contents of the “1.css”, I’m not that ‘ ‘ see 2.css”also have read that.

After to see 2.css”download is finished downloading”1.css”is for.

And to load all the link elements

Must slow down if??
You know, should read see 2.css”two files”1.css”and at the stage of reading how to write multiple link elements in HTML HTML.

Once you know the files that need to be read, downloaded parallel where possible. Therefore, can reduce the time to complete the load.


To prevent slow loading of the external CSS file

It is a way of “do not use the @ import” can be prevent load slow in loading external CSS files, like this one. If you, if you use the @ import

  1. change the way directly read from an HTML link element
  2. Join the CSS file

As for be able to catch either way, please consider.

Furthermore, if the total amount of data is the same whole takes shorter less file number. From the communication server and reduced is has to explain in the article “in”CSS Sprite”image display speed high speed to”. So, how to load whatever “or cannot be integrated with multiple CSS files into one? “” Please consider the point too.

Let’s look at how to prevent slowdowns when loading external JavaScript,.

Loading external JavaScript can be written outside the head element

scripts write to the outside of the head element

Not the mean cannot write in the HTML head element only script element to load external JavaScript file is. Like the right figure, also to write within the body element.

Description of the position of the script element can affect the Web page display speed (the time it takes to complete the display).

page display speed depending on the position of script elements

For example, offer take 5 seconds to load JavaScript files

  1. To load a JavaScript file near the top of the HTML (= head element in)
  2. Load JavaScript files in HTML middle (intermediate a-body element)
  3. To load a JavaScript file (LSAT = </body> tags) to the end of the HTML

So if you write, will display following rough after 3 seconds per ( Firefox while loading = JavaScript files ) , from load start.

1 does not appear at all and display, 3 are all listed on the way 2

Up to finish reading the JavaScript, the above reason is from lockup (draw) the rendering of Web pages and there is description to load the JavaScript file in the HTML,.

No longer introduced and to load external JavaScript files at the top of the HTML, up to finish reading the JavaScript renders pages will be turned into. However, for JavaScript files read from me, read at the end of the HTML in all drawing pages finished the drawing do not stop to wait for the completion of loading JavaScript files.

To prevent slow loading of external JavaScript files

the script finally HTML

To prevent slow time to display complete page by loading JavaScript files, let us as possible to write script element to load external JavaScript file is at the end of the HTML.

I cannot directly affect page rendering, such as scripts, the drive to the end might not go too. However, it would be to write (LSAT = </body> elements) to the end of the HTML source if the content is not so good.

For example,

  • Access analysis script (the script does not affect at all = drawing)
  • Changing the drawing of a particular position by certain conditions, such as a user or time manipulation ) script (scripts from all drawing pages = end function)

Such as the loading at the end are not a problem.

Drawing expected, or if you change the position of loading external JavaScript file, no error occurs drawing on the way to confirm whether ability correctly as such, published ago.

Description of position, affect the speed and reading speed

View (draw) completed and time to complete the load by position and describe how to load the external file, even when the final result is the same, that you like, introduce changes take time. External CSS files, please try be careful to load external JavaScript files, you.

Incoming search terms:

  • external javascript page position (1)