Symfony multiple requests to FOS Routing

ecc

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?

Tomasz Madeyski

FOSRouting while serving routes can work in two ways:

  1. Calling controller which generates routes every request (on the fly). This is convenient for dev environment as it is not cached.
  2. Routes can be dump into static js with 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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony, fos_js_routing and problems with "_locale"

From Dev

Symfony2 FOS Rest bundle routing FileLoaderLoadException controller

From Dev

All apache requests to Symfony Routing Component

From Dev

Symfony 4 routing: multiple params with multiple slashes?

From Dev

How symfony handles multiple bundles routing?

From Dev

Symfony2 Routing issue with multiple bundle and configuration levels

From Dev

Symfony 2, how do I handle routing for multiple domains?

From Dev

Symfony2 FOS, redirect when not logged in

From Dev

FOS\RestBundle, "Unrecognized options" on Symfony2

From Dev

redirect after login fos user symfony

From Dev

Symfony Password Reset without FOS Bundle

From Dev

Symfony2 FOS assigning roles in the controller

From Dev

Symfony2 FOS RestBundle Test

From Dev

Symfony, Fos User Bundle, link to auth/login

From Dev

How to Logout Session Symfony Fos:Userbundle

From Dev

Symfony2 FOS, redirect when not logged in

From Dev

Symfony FOS editing/updating username/email

From Dev

Symfony2 FOS login with role check

From Dev

Symfony FOS UserBundle: override error landing page

From Dev

Routing requests based on url

From Java

MVC routing using Symfony routing

From Dev

how install fos CommentBundle on symfony 2.7.5 that that use fos\RestBundle ^2.0@dev

From Dev

Symfony Routing: Options in Annotations

From Dev

Routing with angular and Symfony

From Dev

Symfony routing not working

From Dev

Issue with Symfony's routing

From Dev

Symfony - Angular routing

From Dev

Routing symfony2

From Dev

Symfony, dynamic routing