Search code examples
asp-classicrefactoringserver-side-includes

validity of classic ASP include pattern


Here is a pattern I am thinking about in ASP :

Imagine you have a file main.asp that contains

<!--#include file="1.asp"-->

code of 1.asp

   ...my code...

Do you think it is valid to refactor this as

main.asp

Dim defined_1_asp = false
<!--#include file="1.asp"-->

1.asp

if (not defined_1_asp) then
    defined_1_asp = true
    ...my code...
end if

This way I could refactor all my SSI includes while making sure they are executed only once. Of course, the content of the includes would be included, but execution would be protected by the if.

I read that the if statement does not have its own scope in classic ASP so it seems to me that the behavior of the code would not be impacted by the refactoring.

Would I hit a bottleneck if the same files are SSI-included several times ?

Thanks a lot for your help,

Jerome Wagner


Solution

  • AFAIK You cannot include code more than once (you will get errors with duplicate identifiers).

    I create classes , creating them if and when needed.