Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Re-usable code 1

Status
Not open for further replies.

arlequin

Programmer
Sep 21, 1999
232
UY
JavaScript People!<br>At work we R using the #include sentence to re-use code into pages.<br>But #include only works in ASPs!!<br>Is there any way to &quot;include&quot; a piece of code&nbsp;&nbsp;avoiding using #include??<br><br>Some pages in our site does not have any programming inside but we MUST use the #include tag to re-use code for the header and footer. And OF COURSE save the pages as ASP.&nbsp;&nbsp;This spends a lot of sys resources and the site performance lows down and I want to keep my pages HTM !!! :((
 
Hmm...<br>If i understand your question correctly, you can just use the &lt;script&gt; tag.<br><br>use it like this:<br>&lt;script language=&quot;javascript&quot; src=&quot;<b>Script URL HERE</b>&quot;&gt;&lt;/src&gt; <p>theEclipse<br><a href=mailto:eclipse_web@hotmail.com>eclipse_web@hotmail.com</a><br><a href=robacarp.webjump.com>robacarp.webjump.com</a><br>**-Trying to build a documentation of a Javascript DOM, crossbrowser, of course. E-mail me if you know of any little known events and/or methods, etc.
 
theEclipse,<br><br>many thanx but....<br><br>I don't wanna insert JavaScript code, just HTML code !!!
 
2 Choices:<br><br>1. Use server-side includes, which requires that your server be set up to parse includes (Historically only .shtml files were parsed for includes, but you can configure the server to parse .htm or .html) The syntax looks like &lt;!--#include virtual=&quot;yourfile.html&quot; --&gt;.&nbsp;&nbsp;This will affect server performance some, though.<br><br>2. Use the Javascript &quot;src=&quot; to execute Javascript code that will write the HTML content into the page. This can behave almost like an include.<br><br>Your external js file.js would look like this:<br><br>document.write(&quot;HTML CODE IN HERE&quot;);<br>document.write(&quot;ANOTHER LINE HERE&quot;);<br>or<br>document.write(&quot;HTML CODE&quot; + javascript variables + &quot;HTML CODE&quot;);<br><br>Actually, to reduce the javascript execution to a minimum, just take out all carriage returns from your HTML code, and put it between the parentheses of one document.write() statement.<br><br>The &lt;script language=&quot;javascript&quot; src=&quot;Script URL HERE&quot;&gt;&lt;/script&gt; line would be placed exactly where you want your HTML to be included.
 
I don't think so ndogg...<br><br>We R running an IIS and FrontPage generates JS files for some dynamic animation and it works perfectly.&nbsp;&nbsp;<font color=red><b>:)</b></font><br><br>Perhaps Nestcape Servers execute JS files faster than IIS, don't really know... :(
 
When used in the manner described in (2) by rycamor, the javascript is executed on the client, not the server. <p>nick bulka<br><a href=mailto:nick@bulka.com>nick@bulka.com</a><br><a href= > </a><br>
 
OK<br><br><font color=red>thanks</font>!!!!<br><br>I WAS SO WRONG !!!<br>Don't know what I was thinking at when say that servers execute JS files..!!
 
&nbsp;&nbsp;&nbsp;&nbsp;Actually; according to a post in another thread...there <i>IS</i> a JS compiler put out by NS for servers-side JS, but I think that is pretty pointless considering that pure Java is faster than even compiled JS & can do just as much, if not more :)<br>&nbsp;&nbsp;&nbsp;&nbsp;Anywise; as far as the possible solutions for placing the headers & footers on your pages: If you use a .JS file and the <FONT FACE=monospace>&lt;script language=javascirpt src='yourfile.js'&gt;</font> tag to place the header & footer in your pages<br>&nbsp;&nbsp;&nbsp;&nbsp;I suggest TWO .js files...one for the header that is referenced by a tag IMMEDIATELY<br>&nbsp;&nbsp;&nbsp;&nbsp;after the <FONT FACE=monospace>&lt;body&gt;</font> tag for the header and one for the footer that is referenced by a tag<br>&nbsp;&nbsp;&nbsp;&nbsp;IMMEDIATELY before the <FONT FACE=monospace>&lt;/body&gt;</font> tag.<br>then the client machine will cache your .JS files in memory and will actually ENHANCE the load time on 99% of client machines over the load time if it were actually a part of the original HTML wource :) <p>-Robherc<br><a href=mailto:robherc@netzero.net>robherc@netzero.net</a><br><a href= shared.freeservers.com/searchmaster.html>SearchMaster Interface...11-in-1</a><br>Wanting to learn Assembler; please e-mail me any tutorials or links for it that are useful to you :)
 
Thinking about this, a plain text JS file should work for your purposes, that is if my assumption about IIS is correct (i.e. it handles JS files in a similar manner as Apache). <p>REH<br><a href=mailto:hawkdogg@crosswinds.net>hawkdogg@crosswinds.net</a><br><a href= by Linux</a><br>Learn Linux and Leave out the Windows :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top