separate scripts vs a few larger general ones


I would like to know if it is more advantageous to have a singular script that contains either one or very few (1-3) functions / classes  or have a larger scripts that contain more functions / classes. in each instance the functions / classes would be related and likely be required in the same documents but with the larger ones i would not nessecarily use everything within them where as the smaller ones i could just include the ones i need.


thanks in advanced?
J NUnicorn wranglerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This question is a little like, "Should I date a blonde or a brunette?"  It depends on personal preference.  Here are my thoughts...

1. Disk I/O operations take a lot of time -- up to 3 orders of magnitude more than in-memory operations.  It follows that autoloaders, numerous include() statements, and the like are expensive in deployed applications.  Visit any WordPress web site to see the effect.

2. Web sites that are built out of parts, but are deployed in combined scripts, can be much faster to load, but require more steps to maintain.  You have to make a "build" yourself -- the automation from autoloaders is not there.

Which do you want?  Fast or easy?
J NUnicorn wranglerAuthor Commented:

fast vs easy is not really what im after im more concerned with efficiency. If a method is faster but requires me to cut corners than i am not interested. However, if fast means more efficient than that is exactly what i am looking at
Dave BaldwinFixer of ProblemsCommented:
In loading time, fast always means more efficient.  However, putting common routines in 'include' files makes it much easier to maintain because you don't have to forget where you are using them.  Every time you edit or change the include file, the changes are automatically 'include'd in every page that uses it.
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Ray PaseurCommented:
fast vs easy is not really what im after
Grab a copy of YSlow and use it to analyze a couple of sites.  I recommend you analyze and to see and compare the behavior of each.  I'm not suggesting that you avoid all include() statements; I'm suggesting that one include() that loads many classes is w-a-a-a-y more efficient than having individual class autoloaders.  If you're not familiar with class autoloaders, read this and also look up Composer.  This is the way many high-level developers are organizing their work today.  I do not think a deployed application should be organized that way, and I think when you do your homework with YSlow you'll come to the same conclusion.
J NUnicorn wranglerAuthor Commented:
Thanks Ray!

Im not loading very many libraries so i dont think i need to worry about composer. The only libraries i really use is jquery and bootstrap.

from what i gather you are suggesting i write a larger resource script and include it rather than individual classes and creating an autoloader function?
Ray PaseurCommented:
Here's the thing as I see it.  If I can have 10 classes in a single script and use include() (really, require_once() but they are essentially the same thing) in a deployed application, I will have better performance than if I have 10 auto-loaders.  OTOH, if I have 10 employees working in different locations on different classes, the auto-loaders will help ensure that the development environment always uses the latest versions of their classes.  The "build" process can usually leave the auto-loader in place, because once the large include() script is built, all of the classes will be declared when they are included, and the auto-loaders will not have to do numerous extra disk searches.

Does that make sense?  Really, I think once you see the output from YSlow you will see the concept very clearly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
J NUnicorn wranglerAuthor Commented:
Thanks a lot !!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.