17

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?

1 Answer 1

14

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?

Sign up to request clarification or add additional context in comments.

2 Comments

Sure! Thank you very much for taking the time to answer this question. The only question I have yet: is it possible to make aliases of a named asset in the asset manager? Because if Bundle1 requires 'jquery' and Bundle2 requires 'j_query' then I would not like to include jQuery twice because of the differences in the required asset name.
Yes, you can use an instance of AssetReference to alias one asset with another name.

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.