0
votes

I'm a bit new to Symfony and I'm don't know what to use for my static file management. I have read about Assets component and the Assetics bundle.

I know that Assets just includes the files and Assetics is a bit smarter as it can combine files and compress images. But I already use compass to minify and combine the css files so therefore Assetics is not really required.

Version control so the url of the static files change to by pass browser cache, is done by both.

Assetics is removed from 2.8 or higher, does this mean it is not best practice anymore?

I need to generate urls on three places:

  • Twig -> Easy to do with both
  • Controller -> Found only a way to do this with Assets
  • In css files -> Believe it is with both not possible

Wat would be the best to use in my case, any advise?

3

3 Answers

1
votes

Assetic can be seen as a way to easily apply filters and compile your assets. The asset component basically is used to manage URL generation. As you said, both nicely are integrated in Twig via extensions, and controllers via the services.

Our application uses compass too, but Assetic makes sure that the compiling happens at the right moment without the need of compass watch at the commandline.

Think most of your questions are answered on:

http://symfony.com/doc/current/cookbook/assetic/asset_management.html

and

http://symfony.com/doc/current/components/asset/introduction.html

0
votes

I've been using the RjFrontendBundle to run the front-end CSS/JS build, and also copy other static content into place from Bower/NPM/local sources. It provides a VersionStrategyInterface for the Assets component that creates, and uses unique filenames in production (renaming the files with an embedded hash, via the GulpJS rev-all package). In dev, it uses the normal filename.

Within CSS files, you can still reference CSS/JS, via a url() function, and the pipeline will rename them appropriately in dev and live.

The GulpJS build tool is used to minify and otherwise prepare the plain files. It comes with a setup console command to build the initial gulpfile.js and can also watch and rebuild files, updating the browser as they are changed, which helps with front-end development workflow.

0
votes

The trend is to use standalone front end tools such as gulp/grunt/sass instead of assetic. The reasons are (probably) as follows:

  • gulp / grunt are independent from the framework, providing the same workflow for the front end guy no matter what underlying framework is used for the backend.
  • assetic has a different workflow than most of the modern tools. It assumes that you will write your script/css includes in the templates. Migrating from assetic to gulp could be a pain for large project.
  • as your project grows, assetic can become kind of slowish... As that happens, you will stop pulling your assets from the controller and start generating them the way gulp or grunt does. In this scenario, gulp and grunt are just better tools.
  • assetic lacks some important features, such as including processed assets into HTML code (inline). Because of the way assetic works (twig tags), it might be difficult to overcome this.

As for generating the URLs: assets are just files in the filesystem. Write a function or twig extension to generate URLs to those files.