Assetic not creating combined links - symfony

Just having a few problems trying to get Assetic to generate the combined links in rendered webpages. The files themselves are being generated fine, but in the web page in the production environment, I'm continuing to see the seperate file URLs (which do not work in production, as those uncombined files aren't available).
In a template, I have:
{% stylesheets
'#TBundle/Resources/public/css/bootstrap/bootstrap.css'
'#TBundle/Resources/public/css/bootstrap/bootstrap-responsive.css'
'#TBundle/Resources/public/css/jquery-selectbox/jquery.selectBox.css'
%}
<link href="{{ asset_url }}" rel="stylesheet" media="screen" />
{% endstylesheets %}
In production, this is still rendered as:
<link href="/css/2f787d0_bootstrap_1.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_bootstrap-responsive_2.css" rel="stylesheet" media="screen" />
<link href="/css/2f787d0_jquery.selectBox_3.css" rel="stylesheet" media="screen" />
Despite that, when I invoke php app/console assetic:dump --env=prod I get:
11:13:43 [dir+] /var/www/tbundle/app/../web/css
11:13:43 [file+] /var/www/tbundle/app/../web/css/2f787d0.css
I'm using the default Assetic settings from Symfony2. Any thoughts on what might be causing this?

I had this exact same problem, and for me the issue was in my app.php file. I was loading the kernel as follows:
$kernel = new AppKernel('prod', true);
It appears as though this caused the function to not run in debug mode and combine the assets. When i changed the second argument to false, the assets successfully combined on production and remained uncombined on dev:
$kernel = new AppKernel('prod', false);
Also, you can pass combine=true as an argument to explicitly request that the assets get combined just to test that this functionality is working properly.

Related

Asset returns error 500 for a stylesheet with Symfony3

I'm encounting a problem with assets. My problem seems simple but I can't find a solution. I have search Google and other earch engines, as well as StackOverflox, Github.
I just want to use the asset function in twig templates. The code is very simmple:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
{% block stylesheets %}{% endblock %}
<link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}" />
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{{ knp_menu_render('AppBundle:MenuBuilder:mainMenu') }}
{% block body %}{% endblock %}
{% block javascripts %}{% endblock %}
</body>
</html>
I just want to add Bootstrap stylesheet in my app. But when I refresh my page, I get an 500 Internal Server Error for the stylesheet. The rest of the page shows up but it can't retrieve the sheet. The URL requested is
http://arthur-dev.lyon-bercy.ratp:84/css/bootstrap.min.css
My development domain is http://arthur-dev.lyon-bercy.ratp:84/. So nothing strange in the requested URL. But shouldn't there be a reference to app_dev.php? And when I manually request http://arthur-dev.lyon-bercy.ratp:84/app_dev.php/css/bootstrap.min.css, the Symfony Framework shouts a
"No route found for "GET /css/bootstrap.min.css"
I have cleared the cache, installed the assets with absolute path or relative path, symlinked or hard linked. Nothing resolved my issue.
I'm using Symfony3.4 with Nginx and PHP FPM 7.2 under docker. Here are the exact configuration files:
config.yml: https://framabin.org/?771da57e9f933f5c#A9RmC/Ld0y8k7SZ5EoWCBkcjVF/VWHRO6+tT7d2e3/s=
composer.json: https://framabin.org/?0a3e9ae8ec9ff32c#gmg7lnD3fAkAlBkX408yn8Jr4buuBEt1GosqvGggvm8=
composer.lock: https://framabin.org/?55a3c320d4e6ee9a#YB0fyupuUJL5SGYeZyJI/jGOf53HTd/xudExwCr9+N8=
docker-compose.yml: https://framabin.org/?0583b288a0b7c071#Z9ATFv8QYmfkTidC8F1xehzfM3SjOtW+rRgop9t6ddU=
PHP dockerfile: https://framabin.org/?dd514d9548b1545b#EEmexWzgNzE2W6ODktu5iB3QWATJGz+xZV7B73Fy2gI=
nginx dockerfile: https://framabin.org/?160536a41c6d857c#iK6w74WKm3Q2OKWSP/j6EPdePvc5avxqgqqX74VF91o=
For Information, I tried with AsseticBundle but I get an issue too :
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_assetic_3d14251_0" as such route does not exist.").
Any help is the most welcome
EDIT: Added link to config.yml file
I have found the solution for my problem. I give here the answer.
As I mentionned in my message I use Docker to create my environment. It is based on Maxpou's Symfony with Docker project (https://github.com/maxpou/docker-symfony).
The project isn't up-to-date with the Symfony 3.4. So there are some correction to do. I will make a PR later but here for information the solution: just add the following line in docker-compose.yml at the nginx level:
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
So now it looks like that:
nginx:
build: nginx
ports:
- 84:80
volumes:
- ${SYMFONY_APP_PATH}:/var/www/symfony
The issue was that Nginx didn't have access to the directory with the assets so it returned a 404 page. Now, the file is available directly in Nginx.

Symfony3 & Assetic : different behavior in dev or prod

I'm working on Symfony 3.4 and Assetic.
Let's say my website is www.mycompany.com and i'm using 2 particular types of asset :
Google web font via #Import() in my main CSS file
Custom CSS fonts, with font files manually uploaded in in web/fonts/
When i visit my website in dev mode www.mycompany.com/app_dev.php/ :
Google fonts are well loaded and work.
Font awesome doesn't work (beacause app_dev.php/fonts/ is 404)
When i visit my website in prod mode www.mycompany.com/ :
Google fonts doesn't work (#import seems not to be loaded...)
Font awesome work (because css files are found in www.mycompany.com/fonts/)
Why this behavior ? For your information, i use Assetic this way to load myu assets :
{% stylesheets '#PimInterfaceBundle/Resources/public/css/*' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
// Same for JS
Thanks.
When using the cssrewrite filter, don't refer to your CSS files using the #XxBundle syntax.
try this
{% stylesheets 'bundles/piminterface/css/*' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}" />
{% endstylesheets %}
here is doc
Including CSS Stylesheets
Fixing CSS Paths with the cssrewrite Filter
Dumping Asset Files in the prod Environment
if this is not working for you then try php bin/console asset:install
in prod php bin/console assetic:dump --env=prod --no-debug
`

Assetic on Symfony won't work in production Symfony

I uploaded my SF Application from my local (machine) to production (Cpanel server)
everything looks fine on production except the css, js, etc. (All files inside the web directory.
I open the var/logs/prod.log just to check whats happening and I find out these errors.
request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "No route found for "GET /stylesheets/base.css" (from "http://example.com/admin/login")" etc.........
Now, what I did is to open the base.html.twig and made changes on the path of css/js files.
From
<link href="{{ asset('stylesheets/base.css') }}" rel="stylesheet" />
To the full directory.
<link href="{{ asset('/home2/swipecom/public_html/web/stylesheets/base.css') }}" rel="stylesheet" />
By the way, here's the directory of the application in the server.
home/swipecom
cache
contactless (Where SF directories live)
- public_html (/web the only SF directory)
var
ssl
tmp
public_ftp
logs
I made it work using this code
<link href="{{ asset('web/stylesheets/base.css') }}" rel="stylesheet" />

Issue loading CSS and JavaScript files in Laravel

I'm having a strange issue in my Laravel 5.2 app. Specifically with loading some CSS and JavaScript files. I have this in the folder public/assets so, I have something like this:
|--public
|----/assets
|-------/css
|------------/auth
|---------------login.css
|----------main.css
|-------/js
|---------email.js
|---------/modules
|------------faq.js
That is my directory, so I'm loading the CSS with:
<link href="{{ URL::asset('assets/css/main.css') }}" rel="stylesheet" type="text/css" />
<link href="{{ URL::asset('assets/css/auth/login.css') }}" rel="stylesheet" type="text/css" />
And the JavaScript files with:
<script src="{{ asset('assets/js/email.js') }}" type="text/javascript"></script>
<script src="{{ asset('assets/js/modules/faq.js') }}" type="text/javascript"></script>
Also I'm loading another files as well but I'm explaining the basic situation. So, the thing is that the load of login.css and faq.js are giving me 404 error but the other files are loaded correctly, I even checked open the files through the absolute paths and they're loaded fine, also I made chown to www-data of the public folder but nothing works, so I don't know why a 404 error is triggered. What else should I check?
In the console of the browser the links that are loaded are:
http://mydomain/assets/js/modules/faq.js
http://mydomain/assets/css/auth/login.css
But they give 404 error, and the other files doesn't
first check those 404 files are in there definitely
check those files have readable permisstion

Path of asset in CSS

I have a css file and an image in a bundle directory according these paths:
My_project
+-src
+-Project
+-MyBundle
+-Resources
+-public
+-css
+-MyCSSfile.css
+-images
+-MyImage.jpeg
In my view I call my css using assetic:
{% stylesheets 'bundles/myBundle/css/MyCSSfile.css' filter='cssrewrite' %}
<link rel="stylesheet" href="{{ asset_url }}"/>
{% endstylesheets %}
In my CSS I use:
background-image: url('../images/background.jpg');
Obviously it doens't work. The url which is returned by symfony is:
"http://localhost:8888/MY_Project/web/bundles/myBundle/css/bundles/myBundle/images/background.jpg".
Any idea? Please
In your case, maybe you should use :
php app/console assets:install
in order to copy or symlink assets in the web/bundles directory.
Try this
php bin/console assetic:dump
and try also to clear your cache

Resources