0

After flushing the static cache files from the System -> Tools -> Cache Management -> Flush Static Files Cache from the admin panel...

enter image description here

magento admin panel is looking like below...

enter image description here

and for the solution i have to run the php bin/magento setup:static-content:deploy command everytime.

When i installed Magento 2, static files were generated automatically and not by running the command.

What i need to do so that it will start generating the static files automatically after i have flushed them from backend? Thanks in advance...

2

After flushing the static files you have three options in terms of regenerating them:

1) Compile using grunt (Or an alternative JS based less compiler) when working locally on a theme etc

2) Deploy the theme using magento's native setup:static:content-deploy command

3) Server/Client Side compilation

To do option 3, you have to ensure that your environment supports the generation of static files. You can find the setup for these in the nginx.conf.example (if using nginx) and the .htacces.sample (if using apache). For example, the nginx.conf.sample has the following section:

location /static/ {
    # Uncomment the following line in production mode
    # expires max;

    # Remove signature of the static files that is used to overcome the browser cache
    location ~ ^/static/version {
        rewrite ^/static/(version\d*/)?(.*)$ /static/$2 last;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

This section essentially routes the request for a file through the pub/static.php which in turn generates the pub/static files with relevant symlinks attached to them (Missing this is most likely the reason yours in not being generated)

  • My co-developer is able to generate the static file without executing any of the command mentioned in 1) and 2).As you have suggested to check the above code in nginx.conf.example file, i have checked that.... and the file has same code as you mentioned above.So not the case of 3). Any other suggestion why it is not generating automatically..as i am new to magento 2....Thanks.. – Bhavesh Tilvani Mar 15 '17 at 5:29
  • I've looked at your image, and it seems like you are using walk or xampp. Both or these tend to use apache. You should therefore check to see that your .htaccess at the root of your project has the equivalent code from the .htaccess.sample file – Richard Cripps Mar 15 '17 at 7:23
  • Wamp* .. Sorry autocorrrect! – Richard Cripps Mar 15 '17 at 7:24
  • No...there are many diffs....in both the files.....and using xampp...btw... – Bhavesh Tilvani Mar 15 '17 at 7:28
  • Int hat case, confirm that the static file routing section is in there and if it isn't, add it in. Hopefully it does the trick! – Richard Cripps Mar 15 '17 at 8:16
0

It seems like you run your magento store in production mode or default mode

In production/default mode once the static file was deleted it never regenerate until you run php bin/magento setup:static-content:deploy

You can use the below command to make ensure about what mode are you runnig?

php bin/magento deploy:mode:show

If it is production/default, change to developer mode it will fix your problem

you can use the below command to set developer mode

php bin/magento deploy:mode:set developer
  • From beginning i have set it to the developer mode, one of my co-developer flushes static files in developer mode from admin panel and he gets all the static content automatically by just refreshing the page ,he does not have to run the command, but in my case i have to run the command... – Bhavesh Tilvani Mar 14 '17 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.