[development] Proper method for including external libraries
James Walker
walkah at walkah.net
Wed Oct 11 18:36:21 UTC 2006
On 11-Oct-06, at 2:00 PM, Johan Forngren wrote:
> I think you can safely include it when you need it.
>
> On 10/11/06, Joseph Bratton <jbratton at c2fs.com> wrote:
> Quick question, what is the "proper" method for including external
> libraries within a drupal module? Should I place a require_once at
> the top of the module, or just at the beginning of any functions
> within the module that use that library? Once at the top of the
> module is cleaner, but it also means that it is loaded on every
> page, whether it is actually used or not.
I have in a couple cases created a _MODULE_init() function that will
load libraries (and perhaps check for their existence and
configuration, etc) on an "as needed" basis. This does have the
benefit of not necessarily including things on the pages when they're
not needed. The one caveat sometimes can be scoping for class
definitions. However, particularly with larger libraries, *not*
having them in RAM for each request is usually a pretty big benefit.
--
James Walker :: http://walkah.net/ :: xmpp:walkah at walkah.net
More information about the development
mailing list