3

I am using jQuery in my Symfony2 application and I have a "ReferenceError: jQuery is not defined" error. I think changing Javascript file load order could fix this.

How could I force to load jQuery Javascript file first in order to avoid such errors? I would like to keep the "js/*" in order to load auto-magically the future new JS files I will put.

Here is stylesheets part of my *.html.twig template:

    {% javascripts
            '@xxxBundle/Resources/public/js/*'
            'js/*'
        %}
            <script type="text/javascript" src="{{ asset_url }}"></script>
    {% endjavascripts %}

And here is current output generated by Symfony2:

<script type="text/javascript" src="/Symfony/web/app_dev.php/js/8d3a8ee_part_2_acidTabs_1.js"></script>
<script type="text/javascript" src="/Symfony/web/app_dev.php/js/8d3a8ee_part_2_jquery-1.6.min_2.js"></script>

1 Answer 1

7

You can list your core dependencies first, then load all others:

{% javascripts
        '@xxxBundle/Resources/public/js/*'
        'js/example_1.js'
        'js/example_2.js'
        ...
        'js/*' %}
        <script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
Sign up to request clarification or add additional context in comments.

1 Comment

What about if example_1.js is in the same directory as * ?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.