Tutorial: Embedding Javascript using Global Content Blocks

General project discussion. NOT for help questions.
Post Reply
kendo451

Tutorial: Embedding Javascript using Global Content Blocks

Post by kendo451 »

I just posted a somewhat controversial tutorial on how to enhance page load time by embedding scripts using Global Content Blocks instead of linking to them externally.

http://blog.arvixe.com/using-global-con ... embedding/

I would appreciate feedback about this technique.

Cheers!
Ken
Wishbone
Power Poster
Power Poster
Posts: 1368
Joined: Tue Dec 23, 2008 8:39 pm

Re: Tutorial: Embedding Javascript using Global Content Bloc

Post by Wishbone »

Why is it controversial?
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: Tutorial: Embedding Javascript using Global Content Bloc

Post by applejack »

As CMS generally loads the body first, by putting the scripts in the head does this in effect mean they are actually at the bottom?

Not sure if your technique makes any difference to the speed, as, are not external files cached by the browser anyhow.

Another important perhaps more so than you mentioned is to host sites on a decent server with something like eAccelerator installed, makes a lot of difference.

Thanks for the CGExtensions minify technique as I didn't know about that.
kendo451

Re: Tutorial: Embedding Javascript using Global Content Bloc

Post by kendo451 »

Hi Applejack,

It is true that CMSMS processes the BODY before the HEAD. However, your conclusion that placing Javascript in the HEAD will therefore load last, does not follow from that.

The reason is that there are two big steps in how a web page gets from CMS Made Simple to the Viewer.

1. CMSMS (Server) generates the page. This is where the BODY is processed before the HEAD. This process is 100% completed before the page is sent to the Viewer (step 2).

2. The Viewer's web browser (Client) fetches the page, parses it, and downloads all the linked resources (scripts, media, css, etc), assembles it and displays it to the Viewer.

Most page optimization is concerned with #2 - designing your page in order to minimize the time it takes to download, assemble and display the page to the viewer.

Unlike the Server side, which completely generates the page before serving it, on the Client side most modern web browsers start displaying the page as soon as they have enough information to build the DOM, and then fill in the other pieces (images, scripts, etc) as they are downloaded. This means the browser will start to parse the page, even before the entire HTML file has downloaded.

Browsers always start with the HEAD and then process the BODY.

Hope that answers your question. :)
applejack
Power Poster
Power Poster
Posts: 1014
Joined: Fri Mar 30, 2007 2:28 am

Re: Tutorial: Embedding Javascript using Global Content Bloc

Post by applejack »

Thanks that is what I actually thought just wasn't 100% sure.
Post Reply

Return to “General Discussion”