Google 그룹스는 더 이상 새로운 유즈넷 게시물 또는 구독을 지원하지 않습니다. 과거의 콘텐츠는 계속 볼 수 있습니다.

Combining javascript files.

조회수 6회
읽지 않은 첫 메시지로 건너뛰기

Barely Audible

읽지 않음,
2008. 12. 15. 오전 7:40:3408. 12. 15.
받는사람
I have three seperate javascript files referenced on some pages - is it
possible to combine them all into one file ?

What shoulld I be aware of when doing this?

--
TTFN
Jim

"Leave the Artillerymen alone, they are an obstinate lot. . ."
-- Napoleon Bonaparte

Jonas Raoni Soares Silva

읽지 않음,
2008. 12. 15. 오전 8:31:0708. 12. 15.
받는사람
On Dec 15, 10:40 am, Barely Audible <somewh...@overthe.rainbow.com>
wrote:

> I have three seperate javascript files referenced on some pages - is it
> possible to combine them all into one file ?

Sure

> What shoulld I be aware of when doing this?

Mainly variables (functions are also variables) with the same name,
but different meanings. So avoid using global variables, try to insert
your things into a "namespace".

Despite this, take care with functions that change the behaviour of
JavaScript basic features and any other unexpected stuffs :D

--
Jonas Raoni Soares Silva
http://jsfromhell.com
http://jonasraoni.org

Henry

읽지 않음,
2008. 12. 15. 오전 8:45:2108. 12. 15.
받는사람
On Dec 15, 12:40 pm, Barely Audible wrote:
> I have three seperate javascript files referenced on some
> pages - is it possible to combine them all into one file ?

Certainly possible. Effective is another matter.

> What shoulld I be aware of when doing this?

If you reference these three JS files from 3 sequential SCRIPT
elements, and you assemble the three files into one in the same order
and then replace the 3 sequential SCRIPT elements with one that
references the new file then the outcome should be identical.

On the other hand, if the SCRIPT elements that impart the existing
files are spread out across a document then many other factors may
come into play. Far too many to be simply listed.

Barely Audible

읽지 않음,
2008. 12. 15. 오전 11:45:5108. 12. 15.
받는사람
Thanks Jonas & Henry - I'm going to give it a try!

--
TTFN
Jim

THE AIR FORCE, aims high, shoots low.

dhtml

읽지 않음,
2008. 12. 18. 오전 12:20:5508. 12. 18.
받는사람
Henry wrote:
> On Dec 15, 12:40 pm, Barely Audible wrote:
>> I have three seperate javascript files referenced on some
>> pages - is it possible to combine them all into one file ?
>
> Certainly possible. Effective is another matter.
>

TO be determined effective, there would have to be a goal stated.

I use ANT to combine scripts at work. I set it up so that I could have
many small files without having to hit the user with too many script
tags, and to allow minifying the combined files.

There are levels of scope for the scripts.

1. application
2. page

Things that are small and simple are easier to maintain and test than
things that are large and complex. Small files is good for development
sanity/code clarity.

Script files are downloaded one at a time. This adversely affects page
load performance.

When the browser encounters a <script> tag while parsing an HTML
document, the script must be downloaded and run before the HTML can
continue rendering.

Combining multiple scripts and css files into one js or css file reduces
the number HTTP requests (2 synchronous per domain) and prevents blocking.

Minified files are significantly smaller (a 24k file may compress to
about 6k).

By reducing the size of cacheable items, they will take less space in
the cache. This will help to increase chances of a user having a primed
cache (scripts that exist in the cache do not need to be downloaded).
So, not only do the minified files download quicker, they are more
likely to stay in the returning user's cache.

Files are build from src -> build -> deploy

Files are combined in the /build directory using the ANT <concat> task.
These concat'd files, by convention, end in "-all.js" (or "-all.css").

Only files ending in -all.js are minified. This is done so that pages
which desire to use more js can combine and then minify that JS. Minfication

Minfication is done using yuicompressor in an ANT <apply> task. The arg
lines can control the level of minification. See
http://www.julienlecomte.net/yuicompressor/README for details.

Since minified files are nearly impossible to debug, we have a request
param nomin. Setting this flag will result in a non-minified version of
the file that was created in the ANT task js_css_build.

Garrett

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >

Thomas 'PointedEars' Lahn

읽지 않음,
2008. 12. 18. 오후 1:20:4808. 12. 18.
받는사람
Henry wrote:
> On Dec 15, 12:40 pm, Barely Audible wrote:
>> I have three seperate javascript files referenced on some
>> pages - is it possible to combine them all into one file ?
>
> Certainly possible. Effective is another matter.

You mean _efficient_ instead, and a correct answer
to the corresponding question is "probably yes".


PointedEars

Bart Lateur

읽지 않음,
2008. 12. 20. 오전 6:24:1408. 12. 20.
받는사람
Jonas Raoni Soares Silva wrote:

>On Dec 15, 10:40 am, Barely Audible <somewh...@overthe.rainbow.com>
>wrote:
>> I have three seperate javascript files referenced on some pages - is it
>> possible to combine them all into one file ?
>
>Sure
>
>> What shoulld I be aware of when doing this?
>
>Mainly variables (functions are also variables) with the same name,
>but different meanings. So avoid using global variables, try to insert
>your things into a "namespace".

Duh! That's exactly the same when they're 3 files instead of 1.

--
Bart.

새 메시지 0개