Let's say I want to develop a Magento extension that interfaces to, say, an Open Source charting package or an image gallery or whatever that is NOT part of the extension itself. When downloaded (separate from the extension) the 3rd party lib comes in its own single .zip with all its .php, .js, .html and .css together.

Do I place on the poor site-owner who wishes to install my extension together with the 3rd party lib, the burden of pulling the original 3rd party .zip apart and make them put .js in /js, .php in /lib, .css in /skin etc?

Or is there a generally accepted "dumping ground" for any 3rd party .zips where one can conveniently unzip the download AS IS and be done with it?

5 Answers 5


I don't know if there is a single correct answer to this question as it really depends on the code that you are including.

If you want to include a 3rd party php library, e.g a sdk for an external API, then it should be put in the /lib directory of your Magento project so it can be included by your extension that consumes it.

However you are also using js and css as examples. If you are using js from third parties in your extension to output code, e.g some js that renders a canvas chart, then this should more than likely be put in the /js directory so it can be included by your extension. For css, it should probably be added to the base/default theme and skin dirs.

Unfortunatley the Magento 1 extension system doesn't make it easy to distribute this kind of thing as the files are spread out through the whole project rather than self contained in a single dir. Tools like Magento Composer Installer and Modman help with this somewhat.


When downloaded (separate from the extension) the 3rd party extensions comes in its own single .zip with all its .php, .js, .html and .css together.

I've always been a fan of divining conventions from the source itself, though it can be ambiguous with Magento 1.

Provided the third-party library license allows for bundling, you should unpack it and repackage it along with your extension, because there's no native mechanism for unpacking a separate sub-library (I might be wrong).

Where these assets go depends on type and the internal organization of the files. Pure JS libraries should go under ./js/. Files which are executed server-side belong under ./lib/, noting that any PHP class under ./lib/ can be autoloaded by the (essentially PSR-0) autoload scheme (ref. Zend Framework 1 autoload convention). Nothing under ./lib/ can be (should be) accessed via the client (ref. ./lib/.htaccess).

  • Thanks Ben. Your answer makes sense, but it does mean that site-owners cannot easily upgrade the 3rd party lib to the latest version, independently of the Magento extension that interfaces to it. Unless the understand intimately how it all hangs together and even then it is pain to put all the bits in the right slots. This is a blessing in the sense that versions of extension and 3rd party lib remain consistent, but a pain when new versions of the 3rd party lib offer bug fixes and new features while continuing backwards compatibility.
    – fris
    Jul 13, 2015 at 1:29
  • 1
    "This is a blessing in the sense that versions of extension and 3rd party lib remain consistent..." That's the ticket! Their changes are your changes. This is all a bit easier in Magento 2 thanks to Composer.
    – benmarks
    Jul 13, 2015 at 1:49

So you want to create an extension and you are using an external resource/package for constructing it. In my opinion, whatever package you have used in your extension, your extension should follow Magento best practices. That means you should separate all js, css, images from the external resource and should place in base\default theme package directories.

ie there is no such unique location exists for placing third party package resources. Ultimately when you deliver a cool extension, all js, css and images related to your extension should be kept in a place where an another developer is normally going to look and which is in almost cases is the base/default theme package.

In short

All your extension js should come under


//for third parties, you can create an inner directory, to specify it

This way, an another developer can easily find js, css and images (of your external resources too) of your extension very easily. Since you are using an extra sub directory to indicate the external resource files inside your extension name directory, it will give others a best clue that your extension is relying on some third party packages.

So I recommend you to separate the external packages and make them a part of your extension so that, an another developer can easily find your dependencies. :-)

EDIT - 1

You should not make your extension burden for your site owner. You can avoid this difficulty by properly align your extension. That means, if you save all related files in the specified directory locations, then what all a site owner should do is, grab your extension and then Merge your extension from the application root directory. ie Align your extension properly. It should look like this.

|        |_____frontend\base\defalt\...
|        |_____adminhtml\base\defalt\...


EDIT - 2

If there are some packages, which should share across all Magento applications (such as a javascript library, or a php package etc), then you can put them in \lib directory.

It is true that, there may be duplicate file exist if two extension rely on the same resource packages. They may use different version of the same resource package too. But basically, your extension should use the resource of your extension only (and can rely on default Magento's resources) and it should not rely on other extension's resources, unless your extension is an "extending version" of a third party extension.

  • Thank you. Your answer favours the developer point of view, rather than the site-owner side. But I guess that's the way it is in Magento? I know of other CMS'es that have agreed places to unzip third party archives/libs, keeping all files together just the way the are in the original.
    – fris
    Jul 13, 2015 at 1:37
  • 1
    Yes. I know it's frustrating to separate out a package resource. Magento demands it. There is no easy way for it. Magento best practices says "You should keep all js, css, images in base\default package". Also see my edit code Jul 13, 2015 at 1:42
  • Hi Rajeev... A further consequence of putting the external resource/lib files under "your_extension" is that it cannot be shared by other extensions that also may use the resource/lib. So you end up with multiple copies, possibly different CLASHING versions, loaded on the same page. Ouch!
    – fris
    Jul 13, 2015 at 1:49
  • see my edits please Jul 13, 2015 at 1:57

Magento has its own package manager called Magento Connect. You should check this guide from the official documentation to fully understand how the package should look. You can pack your module from a Magento installation once you understand the structure.

  • Thank you for your answer but it's not quite what I was asking. It's not about how to package my extension, it's about where in the Magento file tree to put 3rd party files that are NOT part of core or my extension, but need to be included as part of the system. Where do I tell users to put those files? Is there a standard spot (or spots) for 3rd party files?
    – fris
    Jul 12, 2015 at 22:52
  • It actually is related to the link I sent you. Js and css have their own folders for packages just like any other extension file. Php files can be either under the root lib folder or inside the module folder inside a lib folder.
    – mbalparda
    Jul 12, 2015 at 22:54
  • Ok, thank you. So your answer is: Yes Magento site builders must unzip the 3rd party archive, pull the PHP, JS, HTML and CSS parts out of that archive and re-distribute those files in the appropriate slots in the Magento file tree. It is NOT considered best practice to allow the site builder to simply unzip the entire 3rd party archive in some commonly agreed directory designated for this purpose from where the associated extension(s) will include the 3rd party files as needed.
    – fris
    Jul 12, 2015 at 23:21
  • Yes. Everything you described is already covered in the packing process described in the documentation.
    – mbalparda
    Jul 12, 2015 at 23:39
  • Well I've read that documentation, but it doesn't say anything about my question. It only talks about files that are part of the extension you develop and want to package. It doesn't say where to put 3rd party files that are NOT part of the extension, like a calendar or an image gallery or a charting package. You may not want to package these with the extension you're developing, so that they can be updated independently. The question then becomes where to put the third party files? What is the best-practice approach for those?
    – fris
    Jul 13, 2015 at 0:42

Basically Magento uses it's own structure to hold .php, .phtml, js, css, images files.

For magento extension developer it is very important that you follow magento way. Check this link.


  1. Your .php files should go under app/code/community folder
  2. Your js files can go to js folder or in skin/frontend or adminhtml/your_theme_pack/your_theme/js folder
  3. Your css files can go to skin/frontend or adminhtml/your_theme_pack/your_theme/css folder
  4. Your images files can go to skin/frontend or adminhtml/your_theme_pack/your_theme/images folder
  5. Your 'htmlfiles should go toapp/design/frontend or adminhtml/template` folder

PS frontend means if your extension is for front store and adminthml means if your extension is for admin area.

There are specific way to hold these files in magento, so you should follow them.

I also would check if your desired/copying functions are already available in magento/zend framework. For example creating pdf, send email, read xml etc are already build in magento.

Hope this helps.

Update 1

If you want to just hold your files somewhere then you can hold anywhere. You can even create new folder within magento root. But this is not best practice for magento, which will load up your server when executing those files. You want to check this https://magentotherightway.com/

  • Thanks for the link and the explanation. But I'm not asking about the extension itself. I'm asking about where to put the 3rd party code not included in the extension. Is there a commonly agreed SINGLE location for it?
    – fris
    Jul 13, 2015 at 0:52
  • If you want to just hold your files somewhere then you can hold anywhere. You can even create new folder within magento root. But this is not best practice for magento, which will load up your server when executing those files. You want to check this magentotherightway.com Jul 13, 2015 at 0:54
  • Distributed extensions should never install to the local codepool.
    – benmarks
    Jul 13, 2015 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.