Laravel/Vagrant 和 Gulp:CSS 和 JavaScript 文件似乎缓存在某处
Laravel/Vagrant and Gulp: CSS and JavaScript files seem to get cached somewhere
我最近开始使用 Laravel 进行开发,但很快 运行 遇到了使用 Gulp 和 Vag运行t 的问题。问题是当我将 SCSS (SASS) 编译为 css 时,浏览器似乎没有更新 css 文件。该文件正在 vag运行t 中正确同步,并且不会被 NGINX 缓存。我知道这一点是因为我在服务器端禁用了缓存并检查了同步文件夹 /var/www/my-project/public/css 文件夹以查看文件是否已正确编译。
文件只有在我重新加载 vag运行t 框时才能正确加载,这很奇怪,因为同步文件夹在服务器上显示正确编译的文件。清除浏览器中的缓存没有帮助。我不知道问题出在哪里。我用 Google Chrome.
在我的服务器块和 Gulp 文件下方:
NGINX 服务器块(注意这不是 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 任务:
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
}));
});
希望有人能帮帮我。
已找到解决方案!
在您的各种 nginx 配置文件中找到显示 sendfile on
的位置并将其更改为 sendfile off
。
Sendfile 用于“在一个文件描述符和另一个文件描述符之间复制数据”,当 运行 在虚拟机环境中,或者至少当 运行 通过 Virtualbox 时,显然存在一些真正的问题。在 nginx 中关闭此配置会导致通过不同的方法提供静态文件,并且您的更改将毫无疑问地立即反映出来。
来源:https://jeremyfelt.com/2013/01/08/clear-nginx-cache-in-vagrant/
我最近开始使用 Laravel 进行开发,但很快 运行 遇到了使用 Gulp 和 Vag运行t 的问题。问题是当我将 SCSS (SASS) 编译为 css 时,浏览器似乎没有更新 css 文件。该文件正在 vag运行t 中正确同步,并且不会被 NGINX 缓存。我知道这一点是因为我在服务器端禁用了缓存并检查了同步文件夹 /var/www/my-project/public/css 文件夹以查看文件是否已正确编译。
文件只有在我重新加载 vag运行t 框时才能正确加载,这很奇怪,因为同步文件夹在服务器上显示正确编译的文件。清除浏览器中的缓存没有帮助。我不知道问题出在哪里。我用 Google Chrome.
在我的服务器块和 Gulp 文件下方:
NGINX 服务器块(注意这不是 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 任务:
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
}));
});
希望有人能帮帮我。
已找到解决方案!
在您的各种 nginx 配置文件中找到显示 sendfile on
的位置并将其更改为 sendfile off
。
Sendfile 用于“在一个文件描述符和另一个文件描述符之间复制数据”,当 运行 在虚拟机环境中,或者至少当 运行 通过 Virtualbox 时,显然存在一些真正的问题。在 nginx 中关闭此配置会导致通过不同的方法提供静态文件,并且您的更改将毫无疑问地立即反映出来。
来源:https://jeremyfelt.com/2013/01/08/clear-nginx-cache-in-vagrant/