Best practices on developing plugin

I could not find a topic on this, so I'd like to get some sort of list. Especially focussed on developing for best performance.

To get us started, some tips I think are worth considering:

- Register JS in cache and only load it when needed as far as possible in your code

- Do not register functions in start, but in libraries and load those again only when needed, so not in start.php

- Check context where your plugin might be usefull (or not) and break the start routine if not.

- Same for plugins that require login or admin

- Use ElggBatch for possibly long running queries.

- Use ajax for on page toggles, form checks etc..

- Async load javacscript

Well that is my list which I violate myself sometimes :-(  I really like more options and suggestions.

  • I am unsure about the use of CDN's. It has benefits (offload and multiple connections from browser) and drawbacks (dependancy and sometimes decreases page load time)

    Also unsure about extending views or replacing them.

  • I've got a good one

    - just in time. Example, don't register a menu item (especialy in init) but register a hook for 'register' 'menu:something'. This way you don't do a lot of unnessesary stuff.

    - also think about file structure in your plugin

    • put css in 'views/default/css/yourplugin/site.php'
    • put js in 'views/default/js/yourplugin/site.php'

    why? This make it easier for theme developers to bundle all the css they need.