开发者

Dynamically calling JS files to load in classic asp application - what was our developer trying to achieve?

I've recently taken over development of a classic ASP application after the sole developer on the project left. There is the following bit of code which for the life of me I can't work out the benefit of, maybe some of you more experienced guys and gals could shed some light on the logic?

In the head section of our default.asp page, the code calls an another asp page with a parameter in order to load/include some files. This asp page reads the parameter and then selects an array of files. It then loops through this array, and for each object in the array, it performs the following function:

Sub SendFile(ByRef sFilename)
    If Len(sFilename) = 0 Then
        Exit Sub
    End If

    If IsEmpty([__SendFile_sSuffixCompressed]) Then
        [__SendFile_sSuffixCompressed] = ".js"
    End If

    If IsEmpty([__SendFile_fso]) Then
        Set [__SendFile_fso] = Server.CreateObject("Scripting.FileSystemObject")
    End If

    Dim sPath
    sPath = Server.MapPath(sFilename)
    Dim stre开发者_Go百科am
    Dim sData
    Set stream = Server.CreateObject("ADODB.Stream")
    Response.Write sPath
    With stream
        .Charset = "utf-8"
        .Type = 2
        .Open
        .LoadFromFile sPath
        sData = .ReadText
        .Close
    End With

    OurResponse.Write sData
End Sub

I would have thought this would be a way of dynamically loading those files, but wouldn't it be much easier just to have a conditional IF block around a normal <script src"...> line?


A <script src"...> line will load a script from a valid URL, but perhaps this is a way for the web application to include script files on the server that are elsewhere on the filesystem not directly accessible by public URL?

I am not sure why you would want to do this because one could still call this ASP page from a public URL to get the scripts however so it really wouldn't buy you security, just obfuscation.

I am personally a huge fan of deleting code whenever possible. Try replacing this functionality with a conditional script tag like you mentioned on a development environment and test for changes. If their is any hidden reasons for this nonsense then you should be able to find them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜