3

I am developing a script which is in the skin folder. I lost many hours because of the weird caching mechanism of Magento.

I already disabled all the caches in the backend, but it still caches. I opened the developer console and enabled "disable cache" in the browser, but it makes no difference.

It does not use the latest script file, even if I empty the var/cache folder.

I also cleared the Javascript/CSS cache and every possible cache.

How on earth should I develop if it caches so hard? I always have to wait about 1-2 minutes until the file is loaded instead of the cached one.

Is it possible to completely turn it off?

  • Is there any CDN server behind for static files ? – Murtuza Zabuawala Aug 8 '18 at 11:50
  • Actually, browser caching javascripts. – kunj Aug 8 '18 at 11:54
  • You can open that file in browser new tab or refresh that opened JS file for update changes. – kunj Aug 8 '18 at 12:04
  • @kunj, refreshing does not help and the new file is still don't loaded even if I open the developer console and check "disable cache" No, there is no CDN server. – Black Aug 8 '18 at 12:31
  • 2
    I think that's your answer then... That server is doing that caching (maybe a Nginx serving static files such as css, js, etc...) Magento shouldn't cache anything if you disable all cache types. Test that in your local environment to confirm it. Apart from that, if we talk about static files, modern browsers will cache them, unless you have really great skills with your browser's configuration – Raul Sanchez Aug 9 '18 at 10:41
2
+25

Magento 1.9 doesn't have such a rigerous caching mechanism by default as Magento 2 does, so you should be able to load the new JS file by just clearing the cache from the backend or by disabling it completely.

But if this is not casued by Magento's internal cache or the browser cache, then it might be a reverse proxy cache like Varnish or Apache's mod_cache that is providing the old JS file for a certain period of time (1-2 mins like you said) before it is invalidated and refreshed.

This would be a misconfiguration of the reverse proxy. If your server really is using a reverse proxy I suggest disabling it for development purposes, because you'll experience many issues like this while you develop the site (which is a huge time waster and nerve destroyer).

Also just to be safe, I'd recommend trying with a different browser and/or actually clearing the browser cache after a file is changed, since your browser installation might be corrupted and the disable browser cache functionality in developer tools might be bugged.

1

My bet is Magento is not guilty here

Static files are cached by default by most modern browsers (you should play with configuration of the browser you use & see if you can disable that feature, or you can try browsing in incognito mode... although I am not sure that would download all static resources every page load, as you require)

Another possible reason, looking your comments, is some cache system in the server where your project is hosted. Most hosting providers use Nginx as web server for static files. If you inspect with your browser the concrete resource you want to download you'll find info, such Expires header (the time when your browser will download again that resource) or the Web Server serving that (maybe Nginx, or even Varnish...)

Considering all of this, a trick to get a 100% fresh version of your file would be trying to add some parameters when calling it (M2 does that https://docs.magento.com/m2/ce/user_guide/system/static-file-signature.html, so you should look for a similar approach in M1), or simply renaming the file

A workaround, if you can't work in a local environment (where you could control that Nginx / Varnish part...), could be placing your Javascript code in a Magento phtml template (which won't be cached if you have disabled Magento cache types) untill your work is done, and then move it to the right Javascript file

1

Even with all caches disabled, Magento will still cache locale & PDO connections which is a by-product of Zend framework which you can see in lib/. However there should be no blocks/html/etc. being cached.

1) Double check your app/etc/local.xml and review the Cache mechanisms configured. If default, all should be file based under MagentoRoot/var however, there are times when the directory may of not been write-able and reverts to the OS temp folder like /var/Magento/ cleaning this other out (if exists) helps as well.

1a) If the caching mechanisms defined in local.xml differ, such as Reddis you'll want to purge any of those instances as well to be sure. redis-cli for example is quick and easy.

2) Be sure that JavaScript merging is disabled. System > Configuration > "Advanced" Developer > Merge JavaScript.

3) Inspect the HTTP/s response headers on the file in question to determine if any cache/expire values are being set. Specifically Cache-Control: ... that may not be getting cleared on browser end.

4) Use Private/Incognito mode & re-launch when needing to be sure of changes to avoid browser cache & sessions being associated.

0

In order to effectively disable magento caching is to execute a query and directly disable it from the database.

Go to your phpMyAdmin or login to mysql from your terminal and execute:

UPDATE `core_cache_option` SET value=0;

Make sure you remove all contents from var/cache

0

While Development, you must clear the browser cache everytime for static files such as js and css.

If you use chrome you may use ignito mode window every time. On ignito mode browser don't load a cache files even it is stored on browser.

-1

Assuming you have cli (command-line interface) access:

Check if magento is in production or development mode.

Run this command bin/magento deploy:mode:show if you run in production mode run this command bin/magento deploy:mode:set developer

After you did that try this command rm -rf var/cache/* var/generation/* var/page_cache/* var/view_preprocessed/* var/di/* pub/static/* generated/*

This should do the trick.

It's recommended to not disable all caches, in most cases only disable full_page, block_html, layout

  • Im not sure how this works. If I execute bin/magento then I get -bash: bin / magento: file or directory not found – Black Aug 8 '18 at 11:50
  • @black oh wait i see you have a skin folder that means you use magento 1 correct ? – Jordan Aug 8 '18 at 11:54
  • yes exactly, as seen in the tag – Black Aug 8 '18 at 12:24
  • 1
    @Jordan , you have answered for wrong magento version, he is asking solution for magento 1.9 . – Vivek Kumar Aug 8 '18 at 19:26
-1

My solution

  • Pls create a file in magento root and try our code


define("DS", DIRECTORY_SEPARATOR);

function getDir($dir, $subdir=false){

    $root   = scandir($dir);
    $result = array();      

    foreach($root as $value){

        if($value === '.' || $value === '..') {
            continue;
        }


        if(is_dir("$dir".DS."$value")) {

            $result[]   = $subdir ? ($dir . DS . $value) : "Mlx_" . $value;
            if($subdir){
                $result = array_merge($result, getDir("$dir".DS."$value", $subdir));
            }

        }

    }
    return $result;

}

$root   = dirname(__FILE__) . DS;
$path   = array();
$out    = array();
$ext    = getDir($root . 'app' .DS. 'code' .DS. 'Mlx');
$config = [
    'ext'       => ['IO'],
    'remove'    => ['css', 'gen', 'js'] //, 'js', 'tmpl', cache
];

$path['cache'][] = "var".DS."cache";

foreach ($ext as $_ext){
    if(!in_array(str_replace("Mlx_", "", $_ext), $config['ext']))
        continue;

    $shortName  = str_replace("Mlx_", "", $_ext);

    $path['css'][] = "pub".DS."static".DS."adminhtml".DS."Magento".DS."backend".DS."en_US".DS.$_ext.DS."css";
    $path['css'][] = "pub".DS."static".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."css";
    $path['css'][] = "var".DS."view_preprocessed".DS."pub".DS."static".DS."adminhtml".DS."Magento".DS."backend".DS."en_US".DS.$_ext.DS."css";
    $path['css'][] = "var".DS."view_preprocessed".DS."pub".DS."static".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."css";


    $path['js'][] = "var".DS."view_preprocessed".DS."pub".DS."static".DS."adminhtml".DS."Magento".DS."backend".DS."en_US".DS.$_ext.DS."js";
    $path['js'][] = "var".DS."view_preprocessed".DS."pub".DS."static".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."js";
    $path['js'][] = "pub".DS."static".DS."adminhtml".DS."Magento".DS."backend".DS."en_US".DS.$_ext.DS."js";
    $path['js'][] = "pub".DS."static".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."js";


    $path['tmpl'][] = "var".DS."view_preprocessed".DS."css".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."template";
    $path['tmpl'][] = "pub".DS."static".DS."frontend".DS."Magento".DS."luma".DS."en_US".DS.$_ext.DS."template";

    $path['gen'][] = "generated".DS."code".DS."Mlx".DS.$shortName;

}


foreach ($config['remove'] as $type){
    if(isset($path[$type])){
        foreach ($path[$type] as $p){
// use for windown
            $cmd = "RD /s /q {$root}{$p}";
            echo $cmd; echo '<br/>';
            exec($cmd, $out);
// use linux, ubuntu, mac os
$cmd = "rm -rvf {$root}{$p}";
            echo $cmd; echo '<br/>';
            exec($cmd, $out);

        }
    }

}
  • our script will fill all extension in app\code\Mlx
  • you can replace Mlx ~> YourVendor
  • Config module when you dev

Please let me if you good idea

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.