Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

shrink produces javascript that doesn't work #1

Closed
nigelhorne opened this Issue January 27, 2012 · 14 comments

2 participants

Nigel Horne Merten Falk
Nigel Horne

Run this program with output to /tmp/foo.htm. Start firefox. Now load file:///tmp/foo.htm. The display box is empty. If you comment out 'do_javascript => 'shrink',' the display box correctly says 'hello, world'.

#!/usr/bin/perl -wT

use JavaScript::Packer;
use HTML::Packer;

my $text = << 'EOF';




EOF

my $packer = HTML::Packer->init();
$body = $packer->minify(\$text, {
remove_comments => 1,
remove_newlines => 1,
do_javascript => 'shrink',
do_stylesheet => 'minify'
});

print $body;

Merten Falk
Owner

Sorry, I can't reproduce this.

Which module/perl version do you use?

Nigel Horne

The module is JavaScript::Packer, called via HTML::Packer. The version of Perl is 5.14.2.

For some reason github chopped much of the program, so I'm trying again. I think that it's likely that Github is broken and chops HTML. RT is better, but I can't seem to get to use RT from cpan.org for this bug report, it forces me to use Github :-(

#!/usr/bin/perl -wT

use JavaScript::Packer;
use HTML::Packer;

my $text = << 'EOF';

ltHTMLgt
ltBODYgt
ltSCRIPT LANGUAGE="JavaScript" type="text/javascript"gt
function xyzzy() {
alert('hello world');
}

xyzzy();

// document.write('xyzzy();');

lt/SCRIPTgt
lt/BODYgt
lt/HTMLgt

EOF

my $packer = HTML::Packer->init();
$body = $packer->minify(\$text, {
remove_comments => 1,
remove_newlines => 1,
do_javascript => 'shrink',
do_stylesheet => 'minify'
});

print $body;

Merten Falk
Owner

I found the original code in edit mode. I also printed the output to foo.html and opened the file in firefox. But I got the 'hello world' message. The result of your test program is:

<HTML><HEAD><SCRIPT LANGUAGE="JavaScript" type="text/javascript">/*<![CDATA[*/function xyzzy(){alert("hello world")}/*]]>*/</SCRIPT></HEAD><BODY><SCRIPT LANGUAGE="JavaScript" type="text/javascript">/*<![CDATA[*/xyzzy();/*]]>*/</SCRIPT></BODY></HTML>
Nigel Horne

What do you suggest I do?

Merten Falk
Owner

Would be great if you could post the output of your test program. I would also like to know which version of HTML::Packer, JavaScript::Packer and Firefox you use.

Nigel Horne

I have tried and tried to get a small program to reproduce the problem, but I can't. Is there an email address that I can use to send the large program? This is with CGI::Buffer - when it uses do_javascript the output gives lots of undefined calls to functions which do exist, when I don't it doesn't. I'd like a place I can email the script which uses CGI::Buffer. I'm not prepared to put the script on a public forum.

Merten Falk
Owner

Could you please check if version 1.006002 also solves this issue?

Nigel Horne
Merten Falk
Owner

Ok, I downloaded the HTML from http://www.bandsman.co.uk/cgi-bin/bb-links.pl and made some tests. Found out that there was a problem in string concatenation caused by a single + character in a string:

s = name.replace(" ", "+");
document.write(s);
document.write("&amp;address=");

JavaScript::Packer found two strings

", "

and

");
document.write(s);
document.write("

and a + operator in between. So these two strings have been concatenated to

", );
document.write(s);
document.write("

I solved this in 1.006003. I will release it asap.

Merten Falk nevesenin referenced this issue from a commit March 02, 2012
Version 1.006003
- This release fixes issue #1.
- Added additional concat tests.
- Fixed bug in string concatenation. Thanks to Nigel Horne for reporting this issue.
- Tidied up.
686965e
Nigel Horne

Thanks for the new release. I just tried it, but got the same error.

Error: print_band_email is not defined
Source File: http://www.bandsman.co.uk/cgi-bin/bb-links.pl
Line: 16

I turned off and cleared the cache in case that was it, but it wasn't.

Merten Falk
Owner

I forgot to say I removed the <!-- HIDE stuff first.

Nigel Horne

I'll try it again. Be aware that I (like lots of other people I suspect) use the <!-- HIDE technique in many places.

Nigel Horne

This snippet produces broken JavaScript. I think it is related to the same problem:

#!/usr/bin/perl -w

use HTML::Adsense;
use JavaScript::Packer;

my $ad = HTML::Adsense->new('client' => 'foo');
my $text = $ad->render();

JavaScript::Packer->init()->minify(\$text);

print $text;

Merten Falk
Owner

HTML::Adsense produces a <!-- hide html comment within the script tag as well. This is only to prevent script from showing up as text in Netscape 1 and Mosaic. I'm sorry, but I will not support this.

Merten Falk nevesenin closed this March 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.