I have a Printable Version feature on my website. It works great, but the problem is that it takes up to 10 seconds for the stripped version of content to load. This is quite annoying to visitors. On my asp pages I insert these comments before and after the content: <!-- content_starts_here //--> <!-- content_ends_here //--> Here is the code that actually does the work: <%@LANGUAGE=VBScript%> <%Option Explicit%> <% Response.Buffer = True Response.CacheControl = "Private" Response.Expires = -1 If Request.ServerVariables("HTTP_REFERER") <> "" Then ' if this didn't come from anywhere, ignore. Dim strContent Dim xml_http Set xml_http = Server.CreateObject("Microsoft.XMLHTTP") xml_http.Open "GET", Request.ServerVariables("HTTP_REFERER"), False xml_http.Send strContent = xml_http.responseText Set xml_http = Nothing Dim regex Dim reg_matches Dim strtitle Dim strbody 'On Error Resume Next ' Get the body Set regex = New RegExp regex.Pattern = "<!--\s+content_starts_here\s+\/\/-->(.|\n)*<!--\s+content_ends_here\s+\/\/-->" regex.IgnoreCase = True regex.Global = True strbody = strContent Set reg_matches = regex.Execute(strbody) If reg_matches.Count > 0 Then strbody = reg_matches.Item(0).Value End If Set regex = Nothing Set reg_matches = Nothing ' Get the title Set regex = New RegExp regex.Pattern = "<title>(.|\n)*<\/title>" regex.IgnoreCase = True regex.Global = True strtitle = strContent Set reg_matches = regex.Execute(strtitle) If reg_matches.Count > 0 Then strtitle = reg_matches.Item(0).Value End If Set regex = Nothing Set reg_matches = Nothing ' if we didn't get any different content, regex failed. So print ' out the existing content If strContent = strbody Then Response.Write strContent Else 'Print the stripped version Response.Write "<html><head>" & strtitle & "</head><body>" & vbCrLf Response.Write "<base href=""" & GetBaseHref(Request.ServerVariables("HTTP_REFERER")) &""">" & vbCrLf Response.Write strbody Response.Write "<HR><center>" & Request.ServerVariables("HTTP_REFERER") & "</center></body></html>" End If End If '''Given a full URL, gets the base URL. Assumes that URLs to the '''default document is atleast terminated by / Function GetBaseHref(strURL) Dim arrParts, i arrParts = split(strURL,"/") GetBaseHref = "" For i = 0 To (UBound(arrParts)-1) GetBaseHref = GetBaseHref & arrParts(i) & "/" Next End Function %> Can someone please take a look and see what needs to be fixed in order to make the function happen more quickly? Also, what code would I need to add so that the stylesheet is applied? THANKS!
about the stylesheets they have a print version, do a search somewhere and you'll get how to do it about the code, do you have the info in the DB? if yes you better use the DB and not parse the code Microsoft.XMLHTTP
wow, some indenting and white space would make that a whole lot more readable. VB is notoriously slow with string handling so a regular expression is probably a very bad choice. You could achieve the same with the instr() and mid() functions, but you could probably do the whole thing just with the stylesheet by defining a print only stylesheet and declaring the bits you don't want to print as hidden. Try reading round - http://meyerweb.com/eric/articles/webrev/200001.html would be a good start. regards FBJ