Is it possible to describe a library (using hook_libraries_info()) that includes multiple files, but in such a way that you can load the individual files conditionally?

Take, for example, the Flot library: https://github.com/flot/flot
The main library file is jquery.flot.js however, depending on the functionality you want, you may also need to load the jquery.flot.time.js and/or jquery.flot.symbol.js files. You don't want the last two files loaded unless a certain condition is met (e.g. the user selects an option that requires one of these files).

The only ways I can see are either listing all files in the library (in which case it seems they'll all be loaded regardless), or creating separate libraries for each file (which seems unnecessary since most of the info for each library would be the same (name, download URL, version, etc.)).

Comments

Ismail Cherri’s picture

I'm looking for the same functionality, did you succeed in finding a solution?

tstoeckler’s picture

If these files can be used standalone then - yes - I think the correct approach would be to define them as separate files. Sadly, though, it is not only tedious to do this, it is impossible: Libraries API currently does not support multiple libraries being shipped by one download. :-/

See also #2073603: Provide support for PHP file libraries containing multiple sub-libraries

I think we should close this as duplicate but I'll leave that for you to decide in case I've missed something.

tstoeckler’s picture

For asset libraries this is now possible in 8.x-3.x. For D7 I really don't see how we can support this with the current API, unfortunately.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.