1
0
mirror of https://github.com/flarum/core.git synced 2025-10-11 23:14:29 +02:00

Bundle unminified JS; minify via ClosureCompilerService when in production

Falls back to a less effective minification library if ClosureCompilerService errors or is unavailable. Minification takes a while (20 seconds or so), but it only happens when assets are modified. Still, this means enabling/disabling extensions is taking far too long. Possible solutions:

- Don't minify initially; set a process running in the background to do minification, and server unminified assets in the meantime.
- Refactor compiler to send each JS file to CCS individually, only if that particular file has been modified.

flarum/gulp has also been updated to no longer support uglification.

closes #582
This commit is contained in:
Toby Zerner
2015-10-09 00:33:53 +10:30
parent bddbf24055
commit 18def302d6
9 changed files with 55904 additions and 73 deletions

View File

@@ -10,7 +10,6 @@
namespace Flarum\Asset;
use Flarum\Asset\CompilerInterface;
use Illuminate\Support\Str;
class RevisionCompiler implements CompilerInterface
@@ -64,30 +63,41 @@ class RevisionCompiler implements CompilerInterface
*/
public function getFile()
{
$revision = $this->getRevision();
$old = $this->getRevision();
$lastModTime = 0;
foreach ($this->files as $file) {
$lastModTime = max($lastModTime, filemtime($file));
}
$ext = pathinfo($this->filename, PATHINFO_EXTENSION);
$file = $this->path.'/'.substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0);
$current = hash('crc32b', serialize([$lastModTime, $this->getCacheDifferentiator()]));
if (! ($exists = file_exists($file)) || filemtime($file) < $lastModTime) {
$ext = pathinfo($this->filename, PATHINFO_EXTENSION);
$file = $this->path.'/'.substr_replace($this->filename, '-'.$old, -strlen($ext) - 1, 0);
$exists = file_exists($file);
if (! $exists || $old !== $current) {
if ($exists) {
unlink($file);
}
$revision = Str::quickRandom();
$this->putRevision($revision);
$file = $this->path.'/'.substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0);
$this->putRevision($current);
$file = $this->path.'/'.substr_replace($this->filename, '-'.$current, -strlen($ext) - 1, 0);
file_put_contents($file, $this->compile());
}
return $file;
}
/**
* @return mixed
*/
protected function getCacheDifferentiator()
{
return null;
}
/**
* @param string $string
* @return string