HighDots Forums  

Sharing external javascript files

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss Sharing external javascript files in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Heru webforumsuser@macromedia.com
 
Posts: n/a

Default Sharing external javascript files - 07-14-2003 , 02:03 PM






It has been reccomended that I should place all my javascript in external files to speed up loading times. At the moment I have been creating an individual javascript for each page on my site (Using MX). It has ocured to me that much of the javascript for each page looks the same, and I was wondering if similar pages could share the same external javascript.

As I don't understand what most of the javascript means it is difficult for me to tell if the javascript is indeed identical. Most of the pages on my website are based on a few varying formats, so logic would dictate that similar pages could possibly share an external javascript file. If you look at my pages,

http://www.artsablaze.co.uk/about_arts_ablaze.htm

and

http://www.artsablaze.co.uk/david_hier_profile.htm

, both pages are almost identical except for content. There are plenty of pages on my site that are similar to one another, so can they all share a few pages of javascript.


Any advice would be appreciated.

Dave




Referring URLs
http://www.artsablaze.co.uk/
http://www.artsablaze.co.uk/about_arts_ablaze.htm
http://www.artsablaze.co.uk/david_hier_profile.htm



Reply With Quote
  #2  
Old   
DiMa
 
Posts: n/a

Default Re: Sharing external javascript files - 07-14-2003 , 03:39 PM






All that gets put in the external js file are the functions, not the js w/in
the html. So if you are using the same functions on different pages you just
put all the functions into one .js file and link it to all pages. Let's say
every page swaps images, 1 page has a DHTML scroller using LayerAnimagic, they
all us a js-updated clock, 2 pages have a flyout menu using show/hide layers or
autolayers...whatever. Remove all the javascript from between the comment tags
and put it in a new .js file. Then look through the list of functions in your
new file and make sure there aren't any repeats of the same function. All swap
image functions look the same. All show/hide layer functions look the same,
etc.

The start:

function MM_preloadImages or
function MM_findObj(n, d) { //v4.01 or
function P7_autoLayers() { //v1.4 by PVII or
function MM_swapImage() { //v3.0 or
function MM_swapImgRestore() { //v3.0

It's fairly easy to see if there are repeats in there. If it's not, put the
first line of a function into find and replace and click Find. If there's a
duplicate, delete it. Really quite simple, actually.

Then attach it to your pages (I put mine directly beneath my style sheet
links):
<script type="text/javascript" src="yourfile.js"></script>


--
--
DiMa
--------------------
WEB FORUM USERS: Please log on to the Newsgroup for quicker replies to your
posts:
news://forums.macromedia.com/macromedia.dreamweaver
For Answers, check here first:
http://groups.google.com/advanced_group_search?q=+group:macromedia.dreamwea ver
http://www.macromedia.com/support/dreamweaver/technotes.html
http://www.projectseven.com/faqbase
http://www.dreamweaverFAQ.com

http://www.macromedia.com/support/forums/etiquette.htm
DiMa Design > From Lines...to Designs
http://www.dimadesign.net


"Heru" <webforumsuser (AT) macromedia (DOT) com> wrote

Quote:
It has been reccomended that I should place all my javascript in external
files to speed up loading times. At the moment I have been creating an
individual javascript for each page on my site (Using MX). It has ocured to me
that much of the javascript for each page looks the same, and I was wondering
if similar pages could share the same external javascript.
Quote:
As I don't understand what most of the javascript means it is difficult for
me to tell if the javascript is indeed identical. Most of the pages on my
website are based on a few varying formats, so logic would dictate that similar
pages could possibly share an external javascript file. If you look at my
pages,
Quote:
http://www.artsablaze.co.uk/about_arts_ablaze.htm

and

http://www.artsablaze.co.uk/david_hier_profile.htm

, both pages are almost identical except for content. There are plenty of
pages on my site that are similar to one another, so can they all share a few
pages of javascript.
Quote:

Any advice would be appreciated.

Dave




Referring URLs
http://www.artsablaze.co.uk/
http://www.artsablaze.co.uk/about_arts_ablaze.htm
http://www.artsablaze.co.uk/david_hier_profile.htm





Reply With Quote
  #3  
Old   
Heru webforumsuser@macromedia.com
 
Posts: n/a

Default Re: Sharing external javascript files - 07-14-2003 , 05:07 PM



Thank you for the reply DiMa.

Just to get things straight. I should put all the javascript in one .js file, check for repetition and link all the pages to the same .js file. Simple as that!

I presume that the browser would then search for the relevant events and disregard anything that isn't needed.

I shall give it a go. I just wish I had realised my mistake before doing two thirds of my site.

Many Thanks

Dave



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.