473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Include Scripts

Hello,

I am working on a web site where I have a master page.
Most web site pages use this master page as base.

Some scripts are used in all pages ... other just in a few pages.
Should I load all scripts in master page ... I think they are cached
right?

Or should I load the common scripts to all pages in my master page and
then in each page load the scripts that are not used in all pages?

Thanks,
Miguel
Aug 17 '08 #1
5 1272
On Aug 18, 8:43*am, shapper <mdmo...@gmail.comwrote:
Hello,

I am working on a web site where I have a master page.
Most web site pages use this master page as base.

Some scripts are used in all pages ... other just in a few pages.
Should I load all scripts in master page ... I think they are cached
right?
That depends on the size of the scripts and how often they change. It
is faster to put all script into one or two files as it cuts down on
the number of requests. If parts of the script change frequently, you
might want to put those parts in a separate file (if appropriate) to
optimise caching.

Or should I load the common scripts to all pages in my master page and
then in each page load the scripts that are not used in all pages?
If the extra script is small (say less than 8kB), put in the master
script file. If it's big, only load it when needed.

Even very large script files reduce to 20~30kB when minified and
compressed so size isn't really that much of a problem.
--
Rob
Aug 17 '08 #2
On Aug 18, 12:45*am, RobG <rg...@iinet.net.auwrote:
On Aug 18, 8:43*am, shapper <mdmo...@gmail.comwrote:
Hello,
I am working on a web site where I have a master page.
Most web site pages use this master page as base.
Some scripts are used in all pages ... other just in a few pages.
Should I load all scripts in master page ... I think they are cached
right?

That depends on the size of the scripts and how often they change. *It
is faster to put all script into one or two files as it cuts down on
the number of requests. *If parts of the script change frequently, you
might want to put those parts in a separate file (if appropriate) to
optimise caching.
Or should I load the common scripts to all pages in my master page and
then in each page load the scripts that are not used in all pages?

If the extra script is small (say less than 8kB), put in the master
script file. *If it's big, only load it when needed.

Even very large script files reduce to 20~30kB when minified and
compressed so size isn't really that much of a problem.

--
Rob
Is there any tool that merges various Javascript files into one single
file and minifies it?

I suppose that would be the best solution. Then I would use that file
on production mode ...

Thanks,
Miguel
Aug 18 '08 #3
shapper meinte:
Is there any tool that merges various Javascript files into one single
file and minifies it?
JSMin. There are implementations in various languages available. It only
removes comments and blanks and doesn't obfuscate. Combining several
scripts in to one has to be done manually though (my server side script
takes care of that).

Deliver JS files gzipped and you end up with miniscule file sizes. No
need for those idiotic "p,a,c,k,e,r"-scripts.

Gregor
--
http://photo.gregorkofler.at ::: Landschafts- und Reisefotografie
http://web.gregorkofler.com ::: meine JS-Spielwiese
http://www.image2d.com ::: Bildagentur für den alpinen Raum
Aug 18 '08 #4
Or should I load the common scripts to all pages in my master page and
then in each page load the scripts that are not used in all pages?
I prefer that approach. Let each page be responsible for the burdens
it places on resources, both server and bandwidth. Any script
previously loaded is, as you suggested cached. Don't make the request
for an item unless it's required. Not everyone may require everything,
i.e., not all visitors will hit all pages - why make them and your
server pay the expense of unnecessary transfers?

Of course, this depends on whether you are undertaking some radical
minimization approach, such as composing all scripts into a single
file and then minify-ing before service. There is virtue to a smaller
number of separate files, but I'm a little afraid of sites that serve
such bloated masses of content that they need to worry about the tiny
extra volume of bytes that get pushed out in JS files...one fewer
images might be the better option.

In general, I stick to the preference for more files and less
confusion in the support arena. I don't do radical minification with
obfuscation. The prod code needs to look as much like the dev/test
code as possible. My minify-ing only strips non-line-break whitespace
and comments.

Aug 18 '08 #5
In comp.lang.javascript message <61b25f07-ab3a-462b-83df-f33a2c6dd695@34
g2000hsh.googlegroups.com>, Sun, 17 Aug 2008 17:49:08, shapper
<md*****@gmail.composted:
>
Is there any tool that merges various Javascript files into one single
file and minifies it?

I suppose that would be the best solution. Then I would use that file
on production mode ...
Much depends on the sort of people who are tempted to look at and into
your pages. But if your scripts have essential comment and a
reasonably-spaced layout you are more likely to get constructive
feedback on any errors and inefficiencies that they may show. And many
pages nowadays are so bloated with graphics that a small improvement in
script size, though in principle good, will not be significant.
For example, I noticed that JF (*.com) was using new Date("... CST") or
similar for an event occurring non-locally (in fact, over 10^9 km away
IIRC), predicted that Opera would get that wrong, verified the
prediction, mailed him, and it was fixed within an hour or two. But
another site (*.gov), similarly warned about mixing getYear and
getUTCMonth, has not yet fixed it. My js-date2.htm refers. Of course,
they *may* fix it before it next matters, at the Dec/Jan overlap. And
those with UK-like settings will not see any effect.

If your pages are coded as badly as many, you may reasonably want to
hide the script. You cannot make it executable but impossible to be
seen; but you can make it less easy to read so that casual observers may
not bother.

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Aug 18 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Rob Long | last post by:
Hey, I've written a custom HTML library using many PHP scripts as seperate files (just like I'd do a java project) and I'm having some problems where I'm including scripts in different...
43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
9
by: Tom Cat | last post by:
Is there anything wrong with using a lot of include files? On one part of my website, I have a form. The page it posts data to, includes a different file based on some of the values. The...
3
by: Michael | last post by:
There seem to be two ways to include files on the server: 1. <!-- #include file="header.inc" --> 2. <script language="VBScript" runat="server" src="header.inc"></script> What are the differences...
5
by: Bill | last post by:
I have perhaps not explained myself clearly, so I'll try it this way. In the code below, where it says "I'd like to include my navigation bar here" is the place I'd like to insert a navigation bar...
0
by: Tom Bates | last post by:
Can I include the same include files in global.asa that I use in other ..asp scripts? I haven't been able to make it work. My O'Reilly book says that global.asa can have includes, but the syntax...
4
by: Cracker Jacks | last post by:
I am having trouble pointing an ASP file to another ASP for use in the include statement. I do not understand all the different paths that the server or the scripts use. Could someone please...
2
by: Keith Chadwick | last post by:
I have been running some tests with regards to xsl:include and xsl:import with the same results on both and I am wondering if someone can explain this behavior to me! First off the xslt file is...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
7
by: berkshire | last post by:
We recently upgraded php from 4.3.9 to 4.4.7. Everything is working well, except the php scripts running as cronjobs. It appears the problem is that these scripts utilize the include() function...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.