I have a Symfony 2 project that is a bit slow to load. The page is a bit heavy, but I still found it weird to be so slow.
I checked the network inspector in Firefox and noticed that about half the loading time was cause by multiple calls to routing?callback=fos.Router.setData
, each time returning an identical javascript.
For instance, one time there were 12 calls that took 1.92 seconds out of the total 3.84 seconds, effectively doubling the already long loading time...
What are these FOS scripts and why do I need so many of them? Is there something wrong in my Symfony 2 configuration?
FOSRouting
while serving routes can work in two ways:
php app/console fos:js-routing:dump
command.It seems that you're using option number one. Try to use second - this will dump your routes into static js file which will be served instead of controller call. Read docs how to do that.
To keep convenience in dev
env and performance at prod
env you can use this kind of code to include your routes. Just remember to run fos:js-routing:dump
command every deploy to prod:
{% if app.debug %}
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
{% else %}
{% javascripts 'js/fos_js_routes.js' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endif %}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments