Assetic doesn't update styles without cache:clear - php

I have an app.less that imports everything (less) else if I comment a line in app.less app styles doesn't render the commented part, but if I change something in that imported less file, anything changes, I have to do cache:clear and to clear the browser cache to see the new style loaded...

Assets that are imported from another stylesheet (less, sass, whatever) will not be recompiled when they change, even if you use php app/console assets:dump --watch. See another question on StackOverflow and this issue in the AsseticBundle issue queue.

I came upon the same problem. This is caused because LESS is using your window.localstorage to save the rendered css file. For testing you could put in javascript
<script> /* Provisory for dev environment: */ window.localStorage.clear(); </script>
however this causes your page to load really slow. i have not found another options for this just yet.

Related

When running "php bin/console list", Symfony prints the code for several classes inside the "src/Admin"-directory

I've taken over a code base of a Symfony 4.4-project, with a couple of extra bundles installed (Sonata being the biggest one). When I write: php bin/console list, then it prints the source code for several of the classes in the src/Admin-directory. And I can't figure out why.
I've searched the code for print, var_dump and dump, but can't figure out where this is.
I'm not familiar enough with Symfony, to go through the code 'from the top', adding my own dump-statements, narrowing it down, where this code is coming from.
Had this been Laravel, then I would have started in the routes, then moved on to maybe the kernel or middleware, then to the controlles - and in the end the views.
Does anyone have a good suggestion on which files to add dump-statements to, to see where this code is coming from?
... Or if anyone else has a good idea on how to find this code, then I'm all ears.
Is it maybe an entire namespace that is printed? And can one even do that?! Hmm...
This is what it looks like:
You'll get this behavior if the code you've inherited uses short open tags <? but your personal dev environment's PHP installation has them disabled. Run php --ini to find where your ini file is and then edit that to change from this:
short_open_tag = Off
To this:
short_open_tag = On
Alternatively, you could edit all the source files and change the short open tags <? to long open tags <?php.

CSS Cache Laravel

I have a site under Laravel based on a template uploaded on Themeforest. I use the CSS proposed by this template. I would like to set up custom CSS rules but I have the impression that Laravel has a cache. No CSS changes are displayed. I have the problem in two cases: if I make a new CSS file or even if I modify an existing CSS file.
I tried to clear my browser's cache.
I tried to clear Laravel's cache with artisan views:clear and artisan cache:clear.
I also checked that my CSS files were included in my Blade file.
This is strange because if I put CSS directives directly into my Blade file as HTML (style=""") it works. But once it's in an external file it doesn't work.
Do you have any leads ?
Please try this code for the bootstrap cache clear.
php artisan cache:clear
php artisan config:cache
or
php artisan optomize

Clear javascript source cache laravel 5.8

I create company profile website using laravel 5.8 and vue js for make it reactive, it's not SPA(single page application) maybe we can call it hybrid, everything run well in local, after i modify javasacript locally then run a command yarn watch to compile and run my web again it runs well. let's say i have uploaded my project to shared hosting. then i modify my javascript code then re-upload my app.js code and here's a problem. the browser loads my previous app.js not my new app.js. i have cleared browser cache it's sill load the previous app.js. how to solve this problem?
thanks
put a random number at the end of address like this:
<script type="text/javascript" src="app.js?v=12392823"></script>
Better option is to add .version() to your webpack mix file:
mix.js('resources/js/app.js', 'public/js')
.version();
After that, when you call mix('js/app.js') in your view, it will add the cache busting get parameters automatically and the parameter will ONLY change if the file has been changed.

Symfony2 cached controller won't update

I'm quite new to PHP and have received some Symfony2 project to maintain. Now I've found out that when I update foo.html.twig, that page will not change until I perform the command console c:c -e prod. Until then the shown page will be foo.html_.twig (hence the underscore).
The problem is that I've changed a controller, let's say BarController.php, but the new added value in that controller does not work in the .twig file, I think because the BarController_.php did not get updated with the clear cache command. What did I do wrong here?
Edit:
As Nate says it's not Symfony that caches controllers, but at least I see that BarController_.php is much older than BarController.php, and it's the one with the underscore that does not have the newly added value.
Edit 2:
BarController.php and BarController_.php both reside in the same folder.
Sometimes you need to clear cache by your own. You can try
rm -rf app/cache/prod/*
and don't forget to change rights.
Apparently I was completely looking at the wrong places. It had nothing to do with caching at all.
Those underscored files appeared because of my hacky way of 'version control', which meant I copied a file I was going to edit, put '.old' after the filename so I had a backup. For some reason there was created an underscored file for these things.
The problem of not being able to read the getter's value was just a bug in my code.

Have Laravel load an alternate public folder on development machine

We have a build script that minimizes javascript/css and then copies it into the public folder.
What I'd like is for development boxes to load files from the app folder, where the unminimized scripts are stored on dev boxes, but still run the minimized scripts on production.
WHAT I'VE TRIED SO FAR:
-Changing the public path:
if (App::environment() == 'development') {
App::bind('path.public', function () {
return app_path() . '/unminimized';
});
}
This works for anywhere we use public_path(), but the front-end programmer uses relative paths, not URL::asset() (or whatnot), to load javascript (we use a framework, so this isn't easy to change). His javascript is still loaded from the public folder
-Changing nginx:
I've tried changing the root_path in nginx from /website/public to /website/code. This loads the javascript correctly, but then my routes don't fire.
Does anyone have any ideas how to accomplish this?
If you modify nginx to point to /website/code on the dev box and then copy the index.php file from /website/public to /website/code it should fix your routes.
You will need to modify the following lines in index.php:
require __DIR__.'/../bootstrap/autoload.php';
and
$app = require_once __DIR__.'/../bootstrap/start.php';
to match the new location so they can include those files correctly.
Seems rather round about...
Lemme see if i've something right first, are you writing your stuff in pre-compiler languages (scss/sass/less/coffeescript)?
If so then it shouldn't matter what you're doing with the uncompressed stuff since:
You should be testing your minified code before pushing to deploy
You should not be deploying both your minified code and your dev versions
Easiest way i see you solving this problem is using something like gulp-inject write a gulp task that you can pass a flag --dev or --prod which will manage which versions of files are inserted into your blade templates (have it default to --dev).
Naturally it would also be advantagous to write a similar task to undo those changes.
Then if you want to take it a step further have a dedicated VCS and manage your dev and production versions in different 'branches'.

Categories