[thelist] Server page includes: javascript and CSS belong in the header!

Taurus James taurus_james at yahoo.com
Fri Feb 16 16:58:54 CST 2007


--- Will Budreau <Will.Budreau at entrust.com> wrote:

> I would like to import a stylesheet or script using standard
> include headers, but those belong in the <head> only. 
> How do you address this issue? 


Will,

I think I built something similar in ASP.  I have an include
file called "header.asp" that contains the function
"buildHeader(pagename, aIncludes, strMeta, bPopup)".  This
function dynamically builds the page headers down to the closing
head tag (</head>).  

Notice the aIncludes parameter.  I pass in an array of
javascript and css file urls.  Inside the function, I just loop
through the array and write the script tags and links like this:

'----------------
' loop thru includes array
For i = 0  To UBound(aIncludes)
	sInclude = aIncludes(i)

        ' check if include is "link" or "script"
	if instr(1,sInclude,"<link")>0 then
                ' write the link as is for CSS or other
		response.write sInclude & vbCrLf
	else
                ' write the script
		response.write "<scri"
		response.write "pt src='" & g_apphomeurl & sInclude & "'
type='text/javascript'></scri"
		response.write "pt>" & vbCrLf
	end if
next
'----------------

The above code is VBScript in ASP.  My nested content pages call
this function, passing in the appropriate javascript and CSS
URLs.  I have seen a similar concept done in JSP.  I'll try and
dig it up.  

Hope I'm not too far off the mark here.  View source on this
page  to see how the above code rendered the tags.

http://taurusbeats.com/music/

HTH,
Taurus

--
 Taurus M. James 
http://taurusjames.com/
http://taurusbeats.com/
http://www.rocmp3.com/taurusbeats
http://tmjcss.com/






 
____________________________________________________________________________________
Looking for earth-friendly autos? 
Browse Top Cars by "Green Rating" at Yahoo! Autos' Green Center.
http://autos.yahoo.com/green_center/



More information about the thelist mailing list