【问题标题】:Laravel/Vagrant and Gulp: CSS and JavaScript files seem to get cached somewhereLaravel/Vagrant 和 Gulp:CSS 和 JavaScript 文件似乎被缓存在某处
【发布时间】:2019-03-03 18:32:06
【问题描述】:

我最近开始使用 Laravel 进行开发,但很快就遇到了使用 Gulp 和 Vagrant 的问题。问题是当我将我的 SCSS (SASS) 编译为 css 时,浏览器似乎没有更新 css 文件。该文件正在 vagrant 中正确同步,并且不会被 NGINX 缓存。我知道这一点是因为我在服务器端禁用了缓存并检查了同步文件夹 /var/www/my-project/public/css 文件夹以查看文件是否正确编译。

文件只有在我重新加载 vagrant box 时才能正确加载,这很奇怪,因为同步文件夹在服务器上显示了正确编译的文件。清除浏览器中的缓存无济于事。我不知道问题出在哪里。我使用谷歌浏览器。

在我的服务器块和 Gulpfile 下方:

NGINX 服务器块(注意这不是 Laravel 家园):

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 任务:

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
        }));
});

希望有人能帮帮我。

【问题讨论】:

  • 尝试运行php artisan view:clear
  • 不幸的是这不起作用:( @JPark

标签: php laravel nginx gulp vagrant


【解决方案1】:

已找到解决方案!

在你的各种 nginx 配置文件中找到 sendfile on 的位置并将其更改为 sendfile off

Sendfile 用于“在一个文件描述符和另一个文件描述符之间复制数据”,在虚拟机环境中运行时,或者至少在通过 Virtualbox 运行时,显然存在一些实际问题。在 nginx 中关闭此配置会导致静态文件通过不同的方法提供服务,您的更改将立即毫无疑问地反映出来。

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

【讨论】:

    猜你喜欢
    • 2017-07-25
    • 2012-08-24
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 2016-11-26
    • 2016-10-23
    相关资源
    最近更新 更多