<link href="/compressor.asp?file=/styles.css,/jquery/gallerific.css,/jquery/ui/style.css,/highslide/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/compressor.asp?file=/jquery/jquery.js,/jquery/ui/ui.core.js,/highslide/highslide-full.js"></script>
<!--Make sure to change the path to your includes directory-->
<!--#include virtual="/class/compression.asp"-->
<%
Set objCompress = New clsCompress 'Fire up our Class!
'Get our CDS(comma delimited string), and make it an array
Dim FilePath : FilePath = Split(Request.QueryString("file"), ",")
'Pass it to the class
objCompress.strFile = FilePath
'Write out the results!
objCompress.ReturnScripts()
Set objCompress = Nothing 'Cleanup, cleanup, everybody do your stuff
%>
<%
Class clsCompress
Public strFile
Private objFSO, objFile, objRegExp, strCompressedFile, strFileType
Private Sub Class_Initialize()
strCompressedFile = ""
End Sub
Public Sub ReturnScripts()
Set objFSO = CreateObject("Scripting.FileSystemObject")
If IsArray(strFile) Then
For i = 0 To UBound(strFile)
Set objFile = objFSO.OpenTextFile(Server.MapPath(strFile(i)))
strCompressedFile = strCompressedFile & VbCrLf & objFile.ReadAll
Set objFile = Nothing
tmp = Right(strFile(i), 3)
strFileType = Replace(tmp, ".", "")
Next : i = Null
Erase strFile
End If
Set objFSO = Nothing
Select Case UCase(strFileType)
Case "CSS" 'CSS
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "/\*[^*]*\*+([^/][^*]*\*+)*/"
strCompressedFile = objRegExp.Replace(strCompressedFile, "")
Set objRegExp = Nothing
'Strip Line Breaks
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "\n+"
strCompressedFile = objRegExp.Replace(strCompressedFile, "")
Set objRegExp = Nothing
'Strip Tabs
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "\t+"
strCompressedFile = objRegExp.Replace(strCompressedFile, "")
Set objRegExp = Nothing
'Strip Spaces Greater than 2 long
Set objRegExp = New RegExp
objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "\s{2}"
strCompressedFile = objRegExp.Replace(strCompressedFile, "")
Set objRegExp = Nothing
Response.ContentType = "text/css"
Response.Write(strCompressedFile)
Response.Flush
Response.Clear
Case "JS" 'Javascript
'Strip New Lines
strCompressedFile = Replace(strCompressedFile, VbCr, "")
'Strip Spaces Greater than 2 long
strCompressedFile = Replace(strCompressedFile, " ", "")
Response.ContentType = "text/javascript"
Response.Write(strCompressedFile)
Response.Flush
Response.Clear
End Select
End Sub
End Class
%>
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (4)
Author
Commented:Commented:
Commented:
Commented: