I'm trying to work with a geo ip API, and have included the JS for it in my default_head_blocks file, however it is being called after my own geoip-api.js file and therefore it's not picking up the Geo location until after my script has run.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <link src="js/modernizr.js" />
        <script src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js" src_type="url"/>
        <link src="js/geoip-api.js" />


How can I get the external script to be called before my theme file?


I've removed the link from the above code and instead used:

    paths: {
        'maxmind': '//js.maxmind.com/js/apis/geoip2/v2.1/geoip2'

require(['jquery', 'jquery/ui', 'Magento_Ui/js/modal/modal', 'maxmind'], function($, modal){
    #my code goes here;

However it's still running the maxmind JS after my code has run.

1 Answer 1


You could use the requirejs that is included with magento 2.


Put a copy of this file in the root of your theme and then add in the files you need.

Guide to requirejs: http://requirejs.org/docs/start.html

  • Require Js is already in place, but I've had a look at this but it doesn't seem to be able to understand the external file and looks for an internal one. Can you find an example of using this with an externally hosted file? The guide doesn't have one.
    – Aravona
    Aug 25, 2016 at 10:57
  • Hmm, doesn't seem to be working when I add that to my requirejs-config.js file. It keeps looking to a local file in my en_GB folder.
    – Aravona
    Aug 25, 2016 at 11:14
  • Can you share your new code? Have you removed the old references to the files? Aug 25, 2016 at 11:32
  • I adeded the code for requirejs.config to the top of my js file and removed it from the default head blocks xml, which required it but still in the wrong order...
    – Aravona
    Aug 25, 2016 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.