kepler has asked for the wisdom of the Perl Monks concerning the following question:

Greetings

I found in Perl Monks a very good node about this subject, at https://www.perlmonks.org/?node_id=117150

It works very well, with the exception of the removing of comments, that accidently also cuts/removes urls of the form 'http://etc...' that are processed just to 'http'. The other problem I partially fixed, is the case of, for example, an array that is placed in the code in multiline, ending this way (the first lines) in a comma. The script assumes that the lines must terminate only in ';', '{' or '}'. Either way, can someone help me regarding the regex for the removal of comments without removing urls?

I would apreciate it very much.

Thanks, Kepler

Replies are listed 'Best First'.
Re: Compressing/obfuscating Javascript
by marto (Cardinal) on Sep 18, 2020 at 18:45 UTC
Re: Compressing/obfuscating Javascript
by hippo (Archbishop) on Sep 18, 2020 at 19:21 UTC
    Either way, can someone help me regarding the regex for the removal of comments without removing urls?

    See How to ask better questions using Test::More and sample data

    use strict; use warnings; use Test::More; my @cases = ( { in => 'http://etc...', out => 'http://etc...' }, { in => 'foo//bar', out => 'foo' }, ); plan tests => scalar @cases; for my $t (@cases) { my $have = $t->{in}; $have =~ s#(?<!http:)//.*$##; is $have, $t->{out}, "$t->{in} correctly processed"; }

    🦛

Re: Compressing/obfuscating Javascript
by karlgoethebier (Abbot) on Sep 19, 2020 at 16:13 UTC

    See here for the original by Dean Edwards. I wonder what this should be good for. Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Re: Compressing/obfuscating Javascript
by perlfan (Parson) on Sep 20, 2020 at 04:24 UTC
    There are many JavaScript based minification tools, and this should be done once (basically as a compilation step in deployment). It should not have to be done per request. Perl can come in on the bundling and delivery of the minified JavaScript if you have various minified libraries that should be packed into the same request. I've seen this approach work quite successfully by presenting an endpoint that allows for a single request to contain a description of the desired JS library composition wanted; the request handler then slaps together all the requested minified JS sources into a single response. I didn't seem to find this modularized in CPAN, but it can be cobbled together relatively easily.
Re: Compressing/obfuscating Javascript
by Anonymous Monk on Sep 18, 2020 at 18:30 UTC
    https://lmgtfy.app/?q=minify+javascript