2
votes

I'm trying to test my application in a production environment context. The problem is that Assetic is not working properly.

the css files and js files are not loaded.

Here's what I did:

  • I was setted : $kernel = new AppKernel('prod', true);
  • I excecuted the commands:

    php app/console cache:clear --env=prod --no-debug php app/console assetic:dump --env=prod --no-debug

so far, no problems, my files have been created:

01:07:26 [file+] /var/www/visual-immersion/app/../web/js/b0c2086.js
01:07:26 [file+] /var/www/visual-immersion/app/../web/js/a49caf1.js
01:07:26 [file+] /var/www/visual-immersion/app/../web/css/a580ac9.css

But when i launch my web page, no css, no js. if i inspect my source code page, i can see:

                <link rel="stylesheet" type="text/css"href="/css/a580ac9_part_1_home_1.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_layout_2.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_style_3.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_font_4.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_responsive_5.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_animations_6.css">

            <link rel="stylesheet" type="text/css" href="/css/a580ac9_personalized-responsive_7.css">

as if i was in dev env !

So i cleaned my cache in dev env too, and restarted my process to prod env...No success.

Do you know what is problem ?

i add my config.yml :

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }

framework:
    #esi:             ~
    #translator:      { fallback: %locale% }
    secret:          %secret%
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_proxies: ~
    session:         ~
    fragments:       ~

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        [VisualImmersionAdminBundle, VisualImmersionSiteBundle]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: %kernel.root_dir%/Resources/java/compiler.jar
        #yui_css:
        #    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: %kernel.root_dir%/data/data.db3
        # path:     %database_path%

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
        transport: gmail
        username:  [email protected]
        password:  mypassword

Edit:

I retried the procedure with assets: install without success.

Edit 2:

in my web browser dev tool, if i add the line:

<link rel="stylesheet" type="text/css" href="/css/a580ac9.css">

It is work. I really think Assetic load files as dev env instead of prod env. Any idea?

EDIT 3:

I add the layout or managed css files, if it can help ...

{% stylesheets '@VisualImmersionSiteBundle/Resources/public/css/*'  filter='cssrewrite'
            'css/stylesheets/layout.css'
            'css/stylesheets/style.css'
            'css/stylesheets/font.css'
            'css/stylesheets/responsive.css'
            'css/stylesheets/animations.css'
            'css/stylesheets/personalized-responsive.css'
        %}
            <link rel="stylesheet" type="text/css" href="{{ asset_url }}">

        {% endstylesheets %}

EDIT 4:

i tried to change my stylesheets filter like this:

{% stylesheets filter='cssrewrite'
        'css/stylesheets/*'
        'bundles/visualimmersionsite/css/*'
    %}

but no success.

3
I wonder if the use_controller: false works in the config.yml. Because if I understand, Assetic still trying to dynamically load files, right?MeursaultF

3 Answers

2
votes

Try to use:

php app/console assets:install web --symlink

This way, instead of having a copy of each bundle's resources, you'll have a symlink, so there should be no need to update.

From docs:

When using the cssrewrite filter, don't refer to your CSS files using the @AcmeFooBundle syntax.

Try this way:

{% stylesheets 'bundles/acme_foo/css/*' filter='cssrewrite' %}
    <link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
2
votes

Setting prod to false is not what's happening.

You're setting the environment to prod and debug to false:

class Kernel ...

public function __construct($environment, $debug)
1
votes

I stumbled on it by accident:

Assetic not creating combined links

And it actually works. I do not understand anything. For the prod work, you must set 'prod' to false.