I’ve been doing some performance tuning on a large site recently, and one of the problems we had was that clicking pages in edit mode was quite slow. Especially when compared to just clicking around on the site in view mode.
When you click a page in the page tree in edit mode, a few things happen:
- The tree communicates with the other frames using javascript, telling them to reload
- The edit panel loads information and the tabs for the page clicked
- The preview frame shows the page in view mode
The important thing to be aware of – is that all edit panel plug-in’s are loaded and the code in OnInit and OnLoad is executed even though the plug-in is not shown.
So, by clicking a page in the tree, the plug-in might be doing lots of work unnecessary.
In my specific performance case, the plug-in was checking if it should be shown, by implementing the ICustomPlugInLoader interface. The code was calling a web service, which had contention problems, and consequently bad response times.
Additionally, the Load event in the same plug-in made a similar call to the web service, and the page itself made a third call to the service. Add a couple of editors to the mix, and performance went downhill from there.
Of course, improving performance on the web service helps, but of the three calls, only one was really necessary (the one on the page being previewed.)
So how do you prevent your code from running inside your plug-in before it is shown to the editor? PreRender! This event is not fired unless your plug-in is shown to the editor.
You will probably have to think about event order and where to put your logic, but just make sure to avoid the heavy lifting inside the Load event (or ICustomPluginLoader.List.)
Any control events on your plug-in (like button clicked etc) are fired before PreRender, so you can prepare data at this point, or just load initial data if this is the first view of the plug-in.
Note! You cannot rely on IsPostBack. It will always be true (clicking on your tab implies a postback.) Checking this.Visible in the Load event is also futile, it is True even though your plug-in is not shown (Visible is computed later on in the event cycle.)