Just answered the same question here. The 'part_#' string is added when accessing your application in the development environment (app_dev.php
).
By default, {% javascripts %}
will print all your assets/scripts, using a <script>
line for each script. In the production environment, they are combined.
The {% javascripts %}
function acts like a foreach
loop in dev environment, while it will combine all assets in to a single <script>
line in production. If you take a look at the PHP-script in the documentation, you can see that it's using foreach
:
<?php foreach ($view['assetic']->javascripts(
array(
'@AppBundle/Resources/public/js/*',
'@AcmeBarBundle/Resources/public/js/form.js',
'@AcmeBarBundle/Resources/public/js/calendar.js',
)
) as $url): ?>
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach ?>
Your base.html.twig should look like this:
{% javascripts combine=false output="sandbox.js"
'@our_custom_js'
'@fos_js_routes'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
<script src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script>
When the other <script>
is not inside the javascripts
part, it will not be in the loop, so it will be printed only once.