Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minifying options #172

Closed
diegocavalletti opened this issue Apr 12, 2017 · 5 comments
Closed

Minifying options #172

diegocavalletti opened this issue Apr 12, 2017 · 5 comments

Comments

@diegocavalletti
Copy link

It would be nice to have an option to decide which type of compression to apply, this could be like:

Level 1 - just join the resources file (this may be useful when debugging)
Level 2 - Join and strip whitespaces
Level 3 - Current level of compression, so minify + uglify

@jarodium
Copy link

What about files that may have been already minified? In order to identify these cases, for any level, a blacklist of resources that should not be compressed ( but joined ) should be provided

@Ashus
Copy link

Ashus commented Aug 17, 2017

There are severe performance issues if you try to minify bootstrap sources with many files. Sometimes even max_execution_time gets triggered. Maybe detection of .min. in filenames would be enough for skipping minification on minified sources.

@Tabrisrp
Copy link
Contributor

Ignoring already minified file and only concatenating them would definitely be a noticeable performance improvement, especially with heavy files. Ideally .min and -min would be supported natively, and it would be to add custom patterns too

@markseuffert
Copy link

markseuffert commented Aug 23, 2018

How about an alternative? I agree that files that are already minified should not be minified again. Following the advice from issue #158, I let the code calling Minify decide whether to do a full minification or a basic minification. Here's my code for a basic minification:

class MinifyBasic extends Minify {

    // Minify data, remove only comments and empty lines
    public function execute($path = null) {
        $content = "";
        $this->extractStrings('\'"`');
        foreach ($this->data as $source => $data) {
            $data = $this->replace($data);
            $data = preg_replace("/\/\*.*?\*\//s", "", $data);
            $data = preg_replace("/\/\/.*?[\r\n]+/", "", $data);
            $data = preg_replace("/[\r\n]+/", "\n", $data);
            $content .= trim($data);
        }
        return $this->restoreExtractedData($content);
    }
}

@matthiasmullie
Copy link
Owner

I'm going to decline this ticket. I'm not opposed to the idea per se, but:

  • mainly: it would make things a lot less robust: some operations would now have to check if other have or have no been done, which would make things slowed, and possibly cause a lot more bugs eventually
  • there's little need for partial minification anyway (or well, I personally don't see the point: if you want to save bandwidth: minify as much as possible - if you want legible code: don't minify)

The only sensible use case I can think of (and that seems to be echoed in the following comments) is combining new source files (that should be minified) with already-minified (that should not be minified again).
I personally don't believe minifier should check for already-minified files and treat them differently. It's a minifier, and it should try to minify what you throw at it. In my mind, such checks should appear in the code calling minifier (as per @markseu and #158)

I'm going to close this, but feel free to reopen if you feel there's a compelling reason that something along these lines should be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants