Currently i'm doing design of site based on symfony2, question is how to disable cache of css files? Now if i change something in css file - nothing changes in browser. When i try to cache:clear - still nothing.
config.yml:
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: true
#bundles: [ ]
#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"
and in twig
{% stylesheets filter="cssrewrite" output="css/general.css"
"@EveCommonBundle/Resources/public/css/main.css"
"@EveCommonBundle/Resources/public/css/another.css" %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
What must i change to get "latest" css file in browser?
Problem is that when i change @EveCommonBundle/Resources/public/css/main.css
, in web/css
still remain old one (dumped by terminal), and it's not been recreated, that's why no "new changes" shows in browsers, and recreate that file i can only by terminal... how can i get sf2 recreate css files on each F5 in browser (in web/css
folder)?
Problem was.... Uhm, don't even know in what but. Current config.yml and console commands done their job. (means that what ever i change in css it will shows as "online mode" in browser)
parts from config.yml
Also helps (maybe, don't know)
In twig it looks like this
With this params I can create\edit\delete any data from css and it would be show in browser immediately.
PS: I showed code "not common", other settings in config.yml i think the same as base one.
In your dev-environment, i.e. when accessing your site via
app_dev.php
, the paths to the assets are generated dynamically and thus each change should be immediately visible.You can use the following command to automatically create assets (more on this can be found in the cookbook, see link below), but generally this should not be necessary:
When using assetic and you want to see your changes in the prod-environment, you have to dump the assets first to make them accessible:
For more information read the section Dumping Asset Files in How to use Assetic for Asset Management in the cookbook.
If all else fails, you might want to use the following in your templates:
to only use assetic when in production environment.
Caching is a standard browser behavior. You can either clear it manually each time, or set up a cache manifest : https://developer.mozilla.org/en-US/docs/HTML/Using_the_application_cache?redirectlocale=en-US&redirectslug=Offline_resources_in_Firefox This is HTML5 though and is not supported everywhere.
A simple way to disable the caching of files is to change the url each time the file changes : you can append a random string or a version number to your href :
or
The random string is simplier for debugging purpose, since you don't need to update the version number manually each time you change your css. But depending on the size of the string, you might get unlucky and get the same string twice...
if you are working with symfony 2 assets in dev. environment, simply use this command:
ref from : http://symfony.com/doc/2.1/cookbook/assetic/asset_management.html#dumping-asset-files-in-the-dev-environment