Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-19-2002, 12:29 AM   PM User | #1
Vladdy
Senior Coder

 
Join Date: Jun 2002
Location: Nashua, NH
Posts: 1,724
Thanks: 0
Thanked 0 Times in 0 Posts
Vladdy is an unknown quantity at this point
JS File Publisher.

ASP script to publish *.js scripts on your server, stripping off all the comments and extra spaces. Depending on your coding habbits the size can be reduced by a factor of two or so. Also you give some extra headache to those stealing your work .
Code:
<%@ Language =JScript EnableSessionState = False%>
<%
Response.Buffer = true;
Response.Expires = 0;
%>
<!--#include file="FileUpload.asp"-->
<html>
<head>
<title>Publish JavaScript</title>
</head>
<body>
<%
scriptsFolder = 'ClientScripts/';

if(Request.QueryString('Submit')=='True')
  { fileName = fileFields(0,2);
    pFN=/.*\\(.*)/;
    fileName = fileName.replace(pFN,"$1");
    if(fileName.length > 0)
      { code = fileFields(0,1);
%>
<h3>Publishing file: <%Response.Write(fileName);%> </h3>
<p>Orginal Code: (size: <%Response.Write(0.001*code.length);%> KB)</p>
<%      pStartComment = /\/\*/;
        pEndComment = /\*\//;
        pSLComment = /\/\/[^\n]*/g;
        pExtraSpace = /\s+/g;
        pSpace = /\s?([\{\};\=\(\)\\\/\+\*-])\s?/g;
        pieces = code.split(pStartComment);
        code = '';
        for(i=0; i<pieces.length;i++)
          { code += pieces[i].split(pEndComment)[1];
          }
        code = code.replace(pSLComment,'');
        code = code.replace(pExtraSpace,' ');
        code = code.replace(pSpace,'$1');
        savePath = Server.MapPath(scriptsFolder + fileName);
        var fso = Server.CreateObject("Scripting.FileSystemObject");
		var scriptFile = fso.CreateTextFile(savePath, true);
        scriptFile.Write(code);
        scriptFile.Close();
%>
<p>Published file: (size: <%Response.Write(0.001*code.length);%> KB)</p>
<%
      }
    else
      {
%>
<h3>File not found</h3>
<%
      }
 }
else
{
%>
<form action="PublishJS.asp?Submit=True" method="post" enctype="multipart/form-data">
<input type="file" name="File" value="" style="width:100%;" />
<input type="submit" name="Submit" value="Submit" />
</form>
<%
}
%>
</body>
</html>
FileUpload.asp is attached with *.txt extension
Attached Files
File Type: txt fileupload.asp.txt (2.5 KB, 190 views)
__________________
Vladdy | KL
"Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"
Vladdy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:11 PM.


Advertisement
Log in to turn off these ads.