locked
Bing Maps Autosuggest without map-- don't load unused css and javascript RRS feed

  • Question

  • Using Autosuggest without a map. And we're currently using jquery ui autocomplete, so we don't need any css from Microsoft, yet I'm seeing that it's loading multiple css files with class names for MicrosoftMap etc. 

    I'm guessing there's probably at least a few .js files also being loaded that are not needed for the Autusuggest without a map and without using the built in autocomplete from Microsoft (used when one uses the attachAutosuggest method).

    Is there anyway to tell it not to load these resources? It's adding a lot of unnecessary bulk to the page. Maybe a way to specify to not log the entire API and instead only those necessary to bring back autosuggest results?

    current code:

    referencing: https://www.bing.com/api/maps/mapcontrol

    Microsoft.Maps.loadModule('Microsoft.Maps.AutoSuggest',    credentials: 'ourkey', callback: searchModuleLoaded
    });


    Wednesday, June 27, 2018 8:34 PM

Answers

  • All of those resources are loaded as part of the map control API. Note that over 99.9% of users load a map instance after loading the map control script, as such a few optimizations in the loading are done based on that. If you want to optimize for the smallest loading of resources, then don't use the map control, use the services.
    Monday, July 2, 2018 3:49 PM

All replies

  • The CSS and JavaScript you are referring to is loaded as part of the map control SDK before you have loaded any modules. Loading the Autosuggest module might load a little bit of CSS and JavaScript. You will need the JavaScript if you want to use that module. There is no option to not load the CSS, but it is small and also namespaced, so shouldn't cause any issues with perf or otherwise.
    Thursday, June 28, 2018 2:47 AM
  • Thanks for the response.

    Logically, though, why load resources one is not going to use? It's my experience doing so is bad practice. Why load CSS for a map when the implementation does not use the map, but only the auto suggest feature?

    I'd like to request an option then to not load the CSS with the rest of the SDK in the event one is not going to use it. I can't imagine such a conditional option would be tough at all to implement.

    I looked at Google Places and as far as I can tell it only loads CSS directly related to its places autocomplete feature, whereas your SDK loads all of its CSS needed for the map portion itself even if only the autosuggest feature is being used and the map is not.

    See screen shot below of all the additional files that get loaded when using the map control SDK. I count 6 css resources for a total around 140K.  As a designer and developer for sites that see a wide range of users with various speeds, every byte counts for performance. 



    Monday, July 2, 2018 12:21 PM
  • All of those resources are loaded as part of the map control API. Note that over 99.9% of users load a map instance after loading the map control script, as such a few optimizations in the loading are done based on that. If you want to optimize for the smallest loading of resources, then don't use the map control, use the services.
    Monday, July 2, 2018 3:49 PM
  • Ah thanks! Did not realize you could access the autosuggest without maps. do you have a link that shows how to do this?  I could only find: https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/autosuggestuiwithoutmap which still uses the map control.

    Monday, July 2, 2018 5:41 PM
  • I think I'm on the right track, using the Bing REST services via 'https://dev.virtualearth.net/REST/v1/Locations. I have it accepting my credentials but is not returning any results yet... trying what i found: https://stackoverflow.com/questions/13996546/how-can-i-filter-bing-location-api-results-by-user-location-for-auto-complete

    Monday, July 2, 2018 6:38 PM
  • All of those resources are loaded as part of the map control API. Note that over 99.9% of users load a map instance after loading the map control script, as such a few optimizations in the loading are done based on that. If you want to optimize for the smallest loading of resources, then don't use the map control, use the services.

    could you direct me to documentation on how to use the services for autosuggest? Thanks.


    Tuesday, July 10, 2018 6:47 PM
  • Note that over 99.9% of users load a map instance after loading the map control script...

    if this is true and only .1% of users ever load the map control API without using the map then why do you guys specifically give an example of using the AutoSuggest through the map control API WITHOUT A MAP:

    Autosuggest UI(Without Map):  https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/autosuggestuiwithoutmap

    Wednesday, July 11, 2018 12:36 PM
  • Because someone asked for it and it was easy enough to provided.
    Wednesday, July 11, 2018 4:25 PM
  • Ok then how do I use the services for autosuggestion like you mentioned? Are you referring to the REST API services? or something else?
    Wednesday, July 11, 2018 4:48 PM
  • You can use the Bing Maps Location REST API to do autosuggest, but it will likely get expensive. A better option is to use the Azure Maps REST services as they support autosuggest. Here is a code sample: https://azuremapscodesamples.azurewebsites.net/default.aspx#Search%20Autosuggest%20and%20JQuery%20UI
    Thursday, July 12, 2018 3:15 AM
  • Ricky,

    Thanks for the information. Is the following the correct url for Bing Maps Location REST API?

    http://dev.virtualearth.net/REST/v1/Locations

    Thursday, July 12, 2018 12:07 PM