Loading libraries, multiples scripts.

123 views
Skip to first unread message

pec76

unread,
Nov 1, 2012, 5:35:39 AM11/1/12
to google-map...@googlegroups.com
Hello,

I am developping a module for Joomla. Then I cannot control if other Google maps scripts are already loaded by other modules.

I need to include this script :
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true&libraries=places"></script>

But if an other module has already included the same, or without places library, or with another additional library, this generate errors.

What is the good practice to load only the needed code. For exemple If I need only to load the places library, because another extension has already laoded the map api ???

Thanks

pec76

unread,
Nov 8, 2012, 2:50:05 AM11/8/12
to google-map...@googlegroups.com
I my question not clear ?

Andrew Leach

unread,
Nov 8, 2012, 3:44:40 AM11/8/12
to google-map...@googlegroups.com
On 8 November 2012 07:50, pec76 <pel...@gmail.com> wrote:
> I my question not clear ?
>>
>> What is the good practice to load only the needed code. For exemple If I
>> need only to load the places library, because another extension has already
>> laoded the map api ???

Here's the documentation:
https://developers.google.com/maps/documentation/javascript/libraries

It doesn't look like you can add libraries once you have loaded the
API. The solution will be to load all the libraries you are likely to
need, although that does rather negate any benefit.

In fact, there's a feature request for just this functionality at
http://code.google.com/p/gmaps-api-issues/issues/detail?id=3664 to
which you can add your star to show you support it.

pec76

unread,
Nov 8, 2012, 3:53:54 AM11/8/12
to google-map...@googlegroups.com, andrew....@gmail.com
OK. But my problem is not "how to load a library later", but :

In a page if another extension installed on a joomla site (or other), have already loaded the google map api, and if I reload it with an other path, this will crash.

If the other extension use the old method :  maps.google.com/maps/api/js?sensor=true
And my extension use the right method :  maps.googleapis.com/maps/api/js?sensor=true

This generate javascripts errors in console, like "double load library my be cause error" and no map are displayed

The second problem, is if my ext need &libraries=places in addition.... 

:-/

Andrew Leach

unread,
Nov 8, 2012, 4:05:50 AM11/8/12
to google-map...@googlegroups.com
On 8 November 2012 08:53, pec76 <pel...@gmail.com> wrote:
> OK. But my problem is not "how to load a library later", but :

Well in that case your question is definitely not clear!

It appears you are asking about loading an additional library if
another Joomla module has already loaded the API. You can't do that.
You need to load the entire API **once** in the master page in order
that modules can simply find it already loaded and use it.

It would be really good if the API allowed modules to be well-behaved and
(a) load the API if it's not already loaded;
(b) load in any libraries they need which aren't already loaded;
(c) not load anything if they don't actually need to.

Cuurently, none of that is possible. Add a comment and your star to
the feature request. While it's not *just* Joomla or other modular
websites which will benefit, it has a definite application there.
Reply all
Reply to author
Forward
0 new messages