/    Sign up×
Community /Pin to ProfileBookmark

javascript external file

I have one javascript file
It’s a large file and keeps growing as I add new functionality

Is it better to have all your code in file or split over several related files?

Issues:

impact on performance of page
ease of maintenance

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@MikeOSSep 30.2010 — You could try using compressors, they will do stuff like remove comments, whitespace, shorten variable and function names etc, bringing your file size down. Here are some that you can try:

http://www.crockford.com/javascript/jsmin.html - JSMint

http://dojotoolkit.org/docs/shrinksafe/ - Dojo ShrinkSafe

http://developer.yahoo.com/yui/compressor/ - YUI Compressor

Also you can use some http compression, if you're using an apache server lookup mod_gzip and mod_deflate.
Copy linkTweet thisAlerts:
@KorOct 01.2010 — I have one javascript file

It's a large file and keeps growing as I add new functionality

Is it better to have all your code in file or split over several related files?

Issues:

impact on performance of page

ease of maintenance[/QUOTE]


If you keep them in a single external file you gain in loading performance, but the maintenance will be poor. Otherwise, you lose the performance (as the browser has to do repeated requests to the server, one for each JS file), but it would be easier for the coder to maintain, change, debug, etc.

Keep a balance between them - my advice. Split the code, but in not so many separate files.
×

Success!

Help @webacity spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...