0

Is there a way to exclude a js file from the magento merge js file?

We are using Lesti Merge and merging with handles. Everything works fine but I want to exclude jquery from the merge file and load it from the google cdn. Is this possible and ultimately worthwhile?

1 Answer 1

1

You can load jQuery from a CDN with the following layout XML, placed within your <default> handle in local.xml or other layout XML file:

<reference name="head">
    <block type="core/text" name="head.jquery">
        <action method="setText">
            <text><![CDATA[<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script>window.jQuery||document.write('<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">\x3c/script>');</script><script>jQuery.noConflict();</script>]]></text>
        </action>
    </block>
</reference>

Replace the version/URL accordingly.

Is it worthwhile?

Whether or not you will get much of doing this is debatable.

In my experience I've found that it's generally better not to do this; jQuery's size after gzipping is pretty minimal compared to things like product images, and it can slow down local development if you have connection problems while working.

Note: code snippet taken from answer to this question, which appears to be valid.

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.