subject=re: client side includes&in-reply-to=<004d01c087e9$34cdb4c0$188419d4@florida>&references=<004d01c087e9$34cdb4c0$188419d4@florida>

Sorry to butt-in late (almost a year late..) on a party, but I might as well:

I've been looking around for something around the lines of this for a while (a lean, clean way of including URL-Based content into inline  HTML) and found zilch.
My own considerations included:
1. reducing server-side load for reusable code-segments. This is of-course especially relevent when we have complex server-side scripts that generate a finally reusable HTML segment (say, a DB-Generated segment), and yet cannot be pre-rendered  (I know this one was a bit far-fetched).
2. Reducing bandwidth usage in large reusale HTML segments (such as long navigation-bars, long <select> option-lists and in general any comlex form which might be reusable, such as search-engine interface-forms)
You can see, both considerations don't explicitly call for CSIs, but rather for a smart caching method for HTML segments, without breaking up my pages into <IFRAME>s.

So here it is (I guess I'm in a serious lack of self-esteem these days):

Considerations and limitations:
My solution is ASP-based, and incorporates using the MSXMLHTTP object on the client-side.
I know it's proprietry (and not very popular), but for us just-make-the-damn-machine-work-after-I-invested-thousands-on-the-Microsoft-package people, it's clean and simple.
The whole solution relies on the builtin caching of our client-side browser, so any cache limitations set up in the browser-options will take effect here.
Also it is important to note that within files constituting CSIs, there should be a set content-expiration limit so your client WILL SOMETIME IN THE FUTURE get to reload the dynamic-yet-cached content of your CSI.


Outline:
The solution comprises of a client-side Javascrip function called CSInclude(url), which subsequently fetches the appropriate URL and inserts it in place where the function call was placed.


Ta da:
======

function CSInclude(URL){
	var xmlHTTP= new ActiveXObject("Microsoft.XMLHTTP");
	xmlHTTP.open("GET",URL,false);

// Increment semaphore
	CSILoading++;

// Get stuff
	xmlHTTP.send();
	document.write(xmlHTTP.responseText);
}



Sample code:
==========
<html>
<head>
<!------  Define the CSInclude() function. This can be done inline or via a <script src=...> approach    --------->
	<script language=Javascript>
	function CSInclude(url){
	...
	}
	</script>
</head>
<body>
The following is a client-side include:
<hr>
<script language=Javascript> CSInclude("http://www.mySite.com/myCSI/myFile.asp"); </script>
<hr>

...


</body>
</html>




 - Party pooper Avi.

Received on Monday, 17 December 2001 10:19:02 UTC