View Full Version : How to remove comments?

28 Jan 2010, 12:03 PM
I downloaded Ext 3.1, and ran jsbuilder2 on the source using the jsb2 file included in the 3.1 download package:

java.exe -jar jsbuilder2.jar --projectFile "c:\development\js builder\staging\ext.jsb2" --homeDir "c:\development\js builder\compiled"

I then compared the resulting ext-all-debug.js to the ext-all-debug.js in the 3.1 download package. I expected that they would be identical, but they are not. There are commetns speckled throughout the .js created using jsbuilder. I thought Ext uses jsbuilder themselves to create the "-all" files. Is there a way to force comments to be removed?

21 Apr 2010, 6:50 AM
I'd also like to know this if anyone has any ideas?

I'm not concerned if ext-all-debug.js has to be passed through another tool, I'd just like to know what is done by Ext to build the distributable releases, so that I can build patched versions that differ only by the patch and not the presence of comments etc.

Cheers ~o)

29 May 2010, 4:58 AM
Any luck? I'm trying to figure out the same thing here.

31 May 2010, 11:39 AM
Same prob, waiting for issue ...

use seroquel (http://www.buyseroquel.net/how-to-use-seroquel.htm)
soft (http://www.viagrasoft.co.uk/what-is--soft.htm)

31 May 2010, 3:56 PM
I filed a bug report regarding this issue. We should be able to reproduce the ext-all*.js files exactly as ExtJS does.

24 Aug 2010, 6:08 AM
Allright.. this builder thingie stinks and the Ext team is in no hurry to fix things.

Does anyone know of an alternative tool that works?

25 Aug 2010, 5:57 AM
JSBuilder3 is included in the latest Sencha Touch betas and can also be used to build (a pre-alpha) Ext 4 from SVN, but to build Ext 3 you need to convert ext.jsb2 to .jsb3 format.

ps. I wrote a small java app to remove comments and additional whitespace from a .js file:

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.regex.Pattern;

public class CleanJavascript {

private static String read(final String filename) throws IOException {
File file = new File(filename);
long length = file.length();
if (length > Integer.MAX_VALUE) {
throw new IOException("File " + file.getName() + " is too large");
byte[] bytes = new byte[(int) length];
InputStream is = new FileInputStream(file);
try {
int offset = 0;
int numRead = 0;
while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
offset += numRead;
if (offset < bytes.length) {
throw new IOException("Could not completely read file " + file.getName());
} finally {
return new String(bytes, "UTF-8");

private static String clean(final String script) {
return Pattern.compile("/\\*.*?\\*/", Pattern.DOTALL).matcher(script).replaceAll("")
.replaceAll("//.*", "")
.replaceAll("\r\n", "\n")
.replaceAll("\\s+\n", "\n")
.replaceAll("\t", " ")
.replaceAll("\n\n", "\n")
.replaceAll("^\n", "");

private static void write(final String filename, final String data) throws UnsupportedEncodingException, IOException {
File file = new File(filename);
OutputStream os = new FileOutputStream(file);
try {
} finally {

public static void main(String[] args) throws IOException {
write(args[1], clean(read(args[0])));

10 Sep 2010, 7:56 PM

I'm too had this problem, and I've decided to fix it by myself. Couple of hours and...

The main problem is in function writeHeadersToTargets(), which is must write these comments (only?) for the target files.
But, it is not only, it do it for all *.js and *.css files in the deployDir, RECURSIVELY.

What for? I don't know.
But, I think, it should process ONLY target files, but not every one in the deployDir.

Here the quick fix for it:

public static void writeHeadersToTargets() {
/* mivion : Why?
Collection<File> outFiles = FileHelper.listFiles(deployDir, new FilenameFilter() {
private Pattern pattern = Pattern.compile(".*[\\.js|\\.css]");
public boolean accept(File dir, String name) {
return pattern.matcher(name).matches() && !(new File(dir.getAbsolutePath() + File.separatorChar + name).isDirectory());
}, true);

for (File f : outputFiles) { // mivion : was outFiles
if (verbose) { // mivion
System.out.println("Writing license text to: " + f.getAbsolutePath());

String headerContents = FileHelper.readFileToString(headerFile);
String codeContents = FileHelper.readFileToString(f);
FileHelper.writeStringToFile(headerContents, f, false);
FileHelper.writeStringToFile(codeContents, f, true);

And of course, now we know a simple solution:
the deployDir MUST NOT be the SAME as the homeDir.

And there are no more annoying comments in your beloved code.

:) mivion

7 Feb 2011, 9:24 AM
There is also a build i did of JSBuilder2 what takes care of these issues. See the JSBuilder2 bugs thread.