douzhengnao8265 2018-09-27 19:23
浏览 122
已采纳

Laravel / Vagrant和Gulp:CSS和JavaScript文件似乎在某处缓存

I recently started developing in Laravel but quickly ran into a problem with using Gulp and Vagrant. The problem is that when I compile my SCSS (SASS) to css, the browser doesn't seem to update the css file. The file is getting properly synced in vagrant and does not get cached by NGINX. I know this because I disabled caching on the server side and checked the synced-folder /var/www/my-project/public/css folder to see if the file got correctly compiled.

The file only correctly loads when I reload the vagrant box, which is weird as the synced-folder shows the correctly compiled file on the server. Clearing cache in the browser does not help. I have no idea where the problem lies. I use Google Chrome.

Below my server block and Gulpfile:

NGINX server-block (note that this is not Laravel homestead):

location / {
    try_files $uri $uri/ /index.php;
    add_header Last-Modified $date_gmt;
    add_header Cache-Control 'no-store, no-cache, must-revalidate, $date, proxy-revalidate, max-age=0';
    if_modified_since off;
    expires off;
    etag off;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    # With php7.0-fpm:
    fastcgi_pass unix:/run/php/php7.1-fpm.sock;
}

location ~ /\.ht {
    deny all;
}

Gulp task:

gulp.task("sass", function () {
    gulp.src(path.sass.src)
        .pipe(plumber({
            errorHandler: function (err) {
                console.log(err.message);
                this.emit("end");
            }
        }))
        .pipe(sass())
        .pipe(gulp.dest(path.sass.destination))
        .pipe(notify({
            message: "Sass compiled.",
            onLast: true
        }));
});

I hope someone can help me out.

  • 写回答

1条回答 默认 最新

  • doujiao1949 2018-09-27 21:59
    关注

    The solution has been found!

    Find the spot in your assorted nginx config files that says sendfile on and change it to sendfile off.

    Sendfile is used to ‘copy data between one file descriptor and another‘ and apparently has some real trouble when run in a virtual machine environment, or at least when run through Virtualbox. Turning this config off in nginx causes the static file to be served via a different method and your changes will be reflected immediately and without question.

    Source: https://jeremyfelt.com/2013/01/08/clear-nginx-cache-in-vagrant/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置