Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Managing common javascript dependencies in Symfony 2

I would like to know what is the standard best practice for dealing with common JavaScript (and even CSS) dependencies across several Symfony 2 bundles.

According to the Book on the official Symfony site:

A bundle should not embed third-party libraries written in JavaScript, CSS, or any other language.

This seems to be logical, but there is no recommendation on how to actually declare, or require common asset dependencies such as jQuery, or more importantly, particular plugins for jQuery. I've emphasized particular plugins because just including a well known, almost always used JS framework in the application layout would be "sort of okay", but a plugin is required just in case it's going to be used.

So if I shouldn't put it in the Resources directory of my bundle, then my questions are the following:

  • where to put the third party code
  • how do I reference it
  • how should other bundles reference the very same plugin (preferably the same physical file)
  • how not to require the same assets more than once

Without knowing any methods to solve this problem, I've thought of adding instructions to my bundle's documentation to include the required libs in the layout file, but there have to be cleaner solutions.

Any thoughts on this?

like image 247
Imi Borbas Avatar asked Jun 02 '11 23:06

Imi Borbas


1 Answers

A third party plugin that uses Assetic and relies on you to install a dependency should do this by requiring you to have an asset named (for instance) "jquery" in your asset manager. It's up to the application developer to provide this asset in config.yml.

Does that make sense?

like image 136
Kris Wallsmith Avatar answered Oct 07 '22 06:10

Kris Wallsmith