2

I want assetic to output compressed js and css to something like this: v2.3.1/css/whatever.css

Currently this is how I dump my css and js for production: $ php app/console assetic:dump --env=prod --no-debug. But they get dumped into css/ and js/, without the version.

I have read this but it seems to refer to images only, not css/js.

An important reason for doing this is for cache busting/invalidation.

3 Answers 3

3

Yes, known issue... In our production workflow we ended up with such block in bin/vendors script:

if (in_array('--env=dev', $argv)) {
    system(sprintf('%s %s assets:install --symlink %s', $interpreter, escapeshellarg($rootDir . '/app/console'), escapeshellarg($rootDir . '/web/')));
    system(sprintf('%s %s assetic:dump --env=dev', $interpreter, escapeshellarg($rootDir . '/app/console')));
    system(sprintf('%s %s myVendor:assets:install --symlink ', $interpreter, escapeshellarg($rootDir . '/app/console')));
} else {
    system(sprintf('%s %s assets:install %s', $interpreter, escapeshellarg($rootDir . '/app/console'), escapeshellarg($rootDir . '/web/')));
    system(sprintf('%s %s assetic:dump --env=prod --no-debug', $interpreter, escapeshellarg($rootDir . '/app/console')));
    system(sprintf('%s %s myVendor:assets:install ', $interpreter, escapeshellarg($rootDir . '/app/console')));
}

As you can see, we defined our console command, which installs assets into web folder after installing and dumping of Symfony's assets. In the MyVendorCommand script we do something like this:

$version = $this->getContainer()->getParameter('your_version_parameter');
$assetsInstallCommand = $this->getApplication()->find('assets:install');

$commandOptions = $input->getOptions();

$assetsInstallArguments = array(
    'command' => 'assets:install',
    'target' => 'web/version-' . $version,
    '--symlink' => $commandOptions['symlink']
);

$assetsInstallInput = new ArrayInput($assetsInstallArguments);
$returnCode = $assetsInstallCommand->run($assetsInstallInput, $output);
Sign up to request clarification or add additional context in comments.

1 Comment

Oh I see. Well I don't know much about sf2 internals, and also I'm using v2.1 so bin/vendors is gone. But you gave an idea and it worked: I added the symlink creation part to my deployment script (vXXX/css -> css and vXXX/js -> js). Thanks again! =)
1

Ho, its a big Symfony2 bug ! I am not sure anyone reported it !

My solution was to add an alias in the Nginx config, but your is def. cleaner & better.

Comments

0

My workaround is to make a rewriteRule in .htaccess file in order to serve the real file, but accepting the full url with version number. Something like this ...

app/config/config.yml

[...]
engines: ['twig']
assets_version: 20140523  # numeric version
assets_version_format: "assets-%%2$s/%%1$s"
[...]

web/.htaccess

[...]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^assets-([0-9]*)/(.*)$ ./$2 [L]
[...]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.