On Jun 24, 2010, at 22:17 , David Winslow wrote:
> On 06/24/2010 04:09 PM, Andreas Hocevar wrote:
>> During the code review accompanying the viewer/composer refactoring, I
>> noticed that page loading times can be reduced by two simple measures:
>>
>> 1. Do not use IFrames to embed maps
>> ===================================
>>
>> As already done in the SearchTable component [1] (props to ltucker for the
>> great work on this), it is possible to integrate maps directly into web
>> pages. All that needs to be done is create a GeoExplorer(.Viewer)
>> instance/subclass with a proper portalConfig, and Django writing the
>> configuration to the main page's template directly.
>>
> Yep, sounds great. We do need to keep the iframe viewer around to
> support embedding maps in outside web pages though, right? Or do we
> have some new embeddable viewer based on jsonp or something?
Right now we always use a Django template which creates the viewer instance.
This is not so bad IMHO (compared to JSONP or using XHR to load the config),
because it saves us an extra request. The embeddable viewer to use in outside
web pages is embed.html, which is only very little code. But yes, getting rid
of the iframe does not save us from providing a standalone embeddable viewer.
Including a viewer directly in an inside web page should work like this:
<html>
<head>
<!-- css and js resources required for the map -->
<!-- create a viewer instance -->
<script type="text/javascript">
var app;
Ext.onReady(function() {
var config = Ext.apply({
useToolbar: false,
proxy: "/proxy/?url=",
rest: "/maps/",
// tell the map viewer where and how to be rendered
portalConfig: {
height: 300,
renderTo: "embedded_map"
}
}, {{config|safe}});
app = new GeoExplorer.Viewer(config);
});
</script>
</head>
<body>
<p>This is a nice map</p>
<div id="embedded_map"></div>
<p>The map shows blah blah blah</p>
</body>
</html>
The only difference from the current iframe way is that the configuration is
included in the page directly, and we have an "embedded_map" div instead of an
iframe that references a Django endpoint with a configured map.
>
>> 2. Do not load unneeded JS and CSS resources
>> ============================================
>>
>> Currently, every page generated by Django uses a template that includes all
>> JS and CSS resources. The extreme case is the start page: it does not need
>> any of it, but loads all. And there is an IFrame loaded by the page which
>> loads the same components itself.
>>
> Actually it's somewhat complicated to do and still support switching
> between minified and not. Ariel has some ideas for improving the
> situation (based on a Django extension:
> http://code.google.com/p/django-compress/) but I think some discussion
> is in order. In the meantime, I'll take a stab at just breaking things
> up a bit more with our current setup.
Thanks! One idea would be to use minified resources by default, and only use
debug resources if ?debug=true is appended to the url. Would django be able to
handle this?
-Andreas.
>
>> I think these two things are easy to fix for the more Django savvy team
>> members. If you feel like wanting to take this on and have questions, please
>> don't hesitate to contact me.
>>
>> -Andreas.
>>
>> [1] http://bit.ly/aov6xp
>>
>
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.