Stolz / Assets

An ultra-simple-to-use assets management library for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concatenating .js files creates invalid JavaScript

fisharebest opened this issue · comments

I am using 3rd party javascript libraries which are already minified, and which DO NOT contain a final semi-colon or new-line.

Each file is valid, but the concatenation is not. For example, create two such files as follows:

echo -n "x='foo'" > foo.js
echo -n "y='bar'" > bar.js

Now, when foo.js and bar.js are pipelined, the resulting file contains x='foo'y='bar'.

In gatherLinks(), perhaps add $buffer .= "\n";.

commented

This is a JavaScript problem and even the solution for your case is easy I think patching the library to deal with all the possible JS problems is out of the scope. The library itself leverages all the minification to another external library.

Since I recall you are already using the fetch_command config option, you can add the fix yourself:

'fetch_command' => function ($asset) {
    /* ... original code ... */

    return $processed . PHP_EOL;
},

Also, I suggest you to contact the authors of those JS libraries and suggest them to use semicolons because, even they are not required, using them is recommended for many good reasons.

Also, I suggest you to contact the authors of those JS libraries and suggest them to use semicolons because, even they are not required, using them is recommended for many good reasons.

FYI, I see this problem with major libraries, including bootstrap and jquery-migrate.

Thanks for the reminder about the fetch_command option.

commented

Fair enough. I just added the fix. I hope it works for you.

Perfect. Thanks!