这个提高首页速度的方法是让首页的数据从文件读取而不是从数据库中读取,主要用于需要在首页显示新闻标题列表和其他栏目的标题列表,方法的思路就是在保存着这些东西的内容时,同时从数据库中读出要在首页显示的标题,并将标题生成一个js文件,这样只需在首页直接引用这个js文件就可以了。
具体过程如下:(CreateNews.asp)
第一步,新闻保存到数据库,insert语句操作即可。
第二步,从数据库中读取新闻标题、相关链接等字段。
//连接数据库
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "DSN=localhost;DRIVER={SQL Server};UID=sa;PWD=123"
//将新闻标题生成一个js文件
第三步:在首页调用这个js文件即可以。
在需要的地方插入
<script language=JavaScript src=/news_js/TitleLIst.js></script><% set Rsjs3=server.CreateObject("ADODB.RecordSet") Rsjs3.Source="select top "&comnewscount&" ID,Title,type as BigClassName,SmallClassName,InputDate,HitCounts AS Click,image,InputDate,Content from CPA_Info WHERE ((((Look = '1') and (Type=70)) or (news = '1' and LookNews = '1')) and (ismain=0)) order by Ismain DESC,ID desc" Rsjs3.Open Rsjs3.Source,conn,1,1 set fs=server.CreateObject("Scripting.FileSystemObject") FilePath=server.MapPath("LastNewsArea_newapt.js") set JSFile=fs.CreateTextFile(FilePath) JSFile.writeline("document.write("" "")") i = 0 while not Rsjs3.EOF if i >= 0 then BigClassName= Trim(Rsjs3("BigClassName")) SmallClassName=Trim(Rsjs3("SmallClassName")) newsurl="ReadNews.asp?ID=" & Rsjs3("ID") & "&BigClassName=" & Trim(Rsjs3("BigClassName")) & "&SmallClassName=" & Trim(Rsjs3("SmallClassName")) datem=Month(Rsjs3("InputDate")) if datem < 10 then datem="0"&CStr(datem) end if dated=Day(Rsjs3("InputDate")) if dated < 10 then dated="0"&CStr(dated) end if 'datetime="["& Year(Rsjs3("InputDate")) &"-"& datem &"-"& Dated &"]" datetime="[" & datem &"-"& Dated &"]" 'if Rsjs3("image")=>1 then 'img="
","") Title=replace(Title,"
","") STR1="" if year(Rsjs3("InputDate"))=year(date()) and month(Rsjs3("InputDate"))=month(date()) and day(Rsjs3("InputDate"))=day(date()) then HasImg = True ImgStr="
| "")")
JSFile.writeline("document.write("" |
"")") JSFile.writeline("document.write(""" & datetime & """)") JSFile.writeline("document.write("" |
","") Title=replace(Title,"
","") STR1="" if year(Rsjs3("InputDate"))=year(date()) and month(Rsjs3("InputDate"))=month(date()) and day(Rsjs3("InputDate"))=day(date()) then HasImg = True ImgStr="
| "")")
JSFile.writeline("document.write("" |
"")") JSFile.writeline("document.write(""" & datetime & """)") JSFile.writeline("document.write("" |