VB icon

ASP to static HTML for speed

Email
Submitted on: 1/1/2015 12:38:00 AM
By: Found on the World Wide Web (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 1212
 
     If you have a large amount of data to give to the user as HTML and this data needs to change once a day then this will speed up the process for the user. The following code will create a file the first time a page is hit for each day. The upside of doing it this way is you have a record of what the use saw on any given day. The downside is the first person takes the performance hit to write the page and you need to check to make sure the user came to this page first. In other words, if they save yesterdays page as a fovorite then they will see old data unless you redirect. I used the month and day to handle this problem. I did not use the year. There are many other ways to handle this problem. http://www.truegeeks.com/asp/mam/osdoc/osframe.asp
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: ASP to static HTML for speed
' Description:If you have a large amount of data to give to the user as HTML and this data needs to change once a day then this will speed up the process for the user.
The following code will create a file the first time a page is hit for each day.
The upside of doing it this way is you have a record of what the use saw on any given day.
The downside is the first person takes the performance hit to write the page and you need to check to make sure the user came to this page first. In other words, if they save yesterdays page as a fovorite then they will see old data unless you redirect.
I used the month and day to handle this problem. I did not use the year. There are many other ways to handle this problem.
http://www.truegeeks.com/asp/mam/osdoc/osframe.asp
' By: Found on the World Wide Web (from psc cd)
'**************************************

Dim fs, fsmyfile, todayfile, ckdayfile, cr, qt
'Get name of file as it needs to be today
todayfile="Cur"&cstr(month(date()))&cstr(day(date()))
ckdayfile=""&cstr(month(date()))&cstr(day(date()))&""
todayfile=trim(todayfile)&".asp"
'Create FileSystemObject
Set fs = CreateObject("Scripting.FileSystemObject")
 
'File may not be built
On Error Resume Next 
 
'Check to see if we already have the HTML file Built
Set fsmyfile = fs.OpenTextFile("c:\inetpub\scripts\asp\jeff\"+todayfile,1,0)
if err<>0 then		'Need to build today
	fsmyfile.Close	'Close File
	Set fsmyfile = fs.OpenTextFile("c:\inetpub\scripts\asp\jeff\"+todayfile,8,1,0)
	cr=chr(13)	'Save some typing (I'm lazy)
	qt=chr(34)	'The Only way I could get the quote marks correct
	codeout="<%@ LANGUAGE=""VBSCRIPT"" %"&">"&cr
	codeout=codeout&"<%"&cr
	codeout=codeout&"today="&qt&cstr(month(date()))&cstr(day(date()))&qt&cr
	codeout=codeout&cr&"if today<>"&qt&ckdayfile&qt&" then"&cr
	codeout=codeout&"response.redirect("&qt&"wrtest.asp"&qt&")"&cr
	codeout=codeout&"else %"&">"&cr
	fsmyfile.Writeline(""&codeout&cr&_
	"<HTML>"&cr&_
	"<title>Write and Check Raw HTML For Speed</title>"&cr&_
	"<BODY>"&cr&_
	"Hello todays file is called "&todayfile&cr&_
	"</BODY>"&cr&_
	"</HTML>"&cr&_
	"<"&"%End if"&cr&_
	"%"&">")
	fsmyfile.close
	fs.close
	Response.Redirect(todayfile)	'Send them to new file
else
	fsmyfile.close
	fs.Close
	Response.Redirect(todayfile)	'Send them to current file
end if%>	


Other 11 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.