Laravel / Blade缓存CSS文件

O

我正在使用PHP-FPM在Nginx服务器上工作。我安装了Laravel 4.1bootstrap v3.1.1.,这就是问题所在。在过去的30分钟里,我一直在尝试更改我最初声明要检查boostrap的css规则。

.jumbotron{
   background: red; 
}

第一次起作用。超大容器是红色的。因此,我删除了该css值并开始工作,但是无论我使用哪个浏览器,该容器都是红色的。我什至通过Google Chrome浏览器检查工具检查了css文件,并且显示了jumbotron带有时的第一个值background:red我删除了css文件,并将其重命名并添加了新样式,我将chrome配置为不缓存页面。但是还是一样的价值。我现在确信,Laravel保留了第一个样式声明的缓存。

有什么办法可以禁用此功能吗?

托蒂梅德利

一般说明

当您访问Laravel Blade视图时,它将生成一个临时文件,因此不必在每次访问视图时都处理Blade语法。这些文件app/storage/view以文件名(即文件路径的MD5哈希)存储在文件中。

通常,当您更改视图时,Laravel会在下次访问视图时自动重新生成这些文件,然后一切正常。通过比较通过该filemtime()函数生成的文件和视图的源文件的修改时间来完成此操作在您的情况下,可能是有问题,并且没有重新生成临时文件。在这种情况下,您必须删除这些文件,以便可以重新生成它们。它没有任何害处,因为它们是从您的视图自动生成的,并且可以随时重新生成。它们仅用于缓存目的。

通常,它们应该自动刷新,但是如果它们卡住并且遇到类似问题,则可以随时删除这些文件,但是正如我所说的,这些只是很少见的例外。

代码分解

以下所有代码均来自laravel/framerok/src/Illuminate/View/我在原件上添加了一些额外的注释。

取得视野

Engines/CompilerEngine.php我们拥有的主要代码开始,我们需要了解其机制。

public function get($path, array $data = array())
{
    // Push the path to the stack of the last compiled templates.
    $this->lastCompiled[] = $path;

    // If this given view has expired, which means it has simply been edited since
    // it was last compiled, we will re-compile the views so we can evaluate a
    // fresh copy of the view. We'll pass the compiler the path of the view.
    if ($this->compiler->isExpired($path))
    {
        $this->compiler->compile($path);
    }

    // Return the MD5 hash of the path concatenated
    // to the app's view storage folder path.
    $compiled = $this->compiler->getCompiledPath($path);

    // Once we have the path to the compiled file, we will evaluate the paths with
    // typical PHP just like any other templates. We also keep a stack of views
    // which have been rendered for right exception messages to be generated.
    $results = $this->evaluatePath($compiled, $data);

    // Remove last compiled path.
    array_pop($this->lastCompiled);

    return $results;
}

检查是否需要再生

这将在中完成Compilers/Compiler.php这是一项重要功能。根据结果​​,将决定是否应重新编译视图。如果返回false而不是返回true,则可能是无法重新生成视图的原因。

public function isExpired($path)
{
    $compiled = $this->getCompiledPath($path);

    // If the compiled file doesn't exist we will indicate that the view is expired
    // so that it can be re-compiled. Else, we will verify the last modification
    // of the views is less than the modification times of the compiled views.
    if ( ! $this->cachePath || ! $this->files->exists($compiled))
    {
        return true;
    }

    $lastModified = $this->files->lastModified($path);

    return $lastModified >= $this->files->lastModified($compiled);
}

重新产生检视

如果该视图已过期,它将被重新生成。Compilers\BladeCompiler.php我们看到,通过所有刀片的关键字,编译器将循环,并最终回馈包含编译PHP代码的字符串。然后它将检查是否设置了视图存储路径,并使用一个文件名将该文件保存在该文件名中,该文件名是视图文件名的MD5哈希值。

public function compile($path)
{
    $contents = $this->compileString($this->files->get($path));

    if ( ! is_null($this->cachePath))
    {
        $this->files->put($this->getCompiledPath($path), $contents);
    }
}

评估

最后在Engines/PhpEngine.php视图中进行评估。它进口传递到与视图中的数据extract(),并include与在传递路径的文件try,并catch与所有的例外handleViewException()是再次抛出异常。也有一些输出缓冲。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

获取文件LARAVEL的BLADE

来自分类Dev

Laravel Blade @include .html文件

来自分类Dev

删除Laravel中的缓存文件

来自分类Dev

Laravel Blade指令可以正确地附加到“ public”文件夹中的CSS样式模板

来自分类Dev

在laravel-blade中生成动态CSS类

来自分类Dev

如何在Laravel Blade语法按钮中添加内联CSS?

来自分类Dev

Laravel Blade不包含模板中存在的CSS和.js

来自分类Dev

Laravel Blade 未在特定页面上显示 CSS

来自分类Dev

如何在Laravel的Views / Blade文件中查询表

来自分类Dev

如何在脚本文件中使用Laravel Blade?

来自分类Dev

Laravel Blade:尝试是否存在导入的php文件

来自分类Dev

如何在Laravel的Views / Blade文件中查询表

来自分类Dev

在 Laravel .blade 文件中使用 DB 是安全的吗?

来自分类Dev

从 Laravel Blade 文件导入一个 Vue js 组件

来自分类Dev

Laravel Blade:@endsection与@stop

来自分类Dev

Laravel 4 Blade BUG

来自分类Dev

Laravel Blade HTML图像

来自分类Dev

Laravel Blade问题

来自分类Dev

Laravel Blade 模板与 jQuery

来自分类Dev

Laravel Blade 如果条件

来自分类Dev

Blade 不渲染 Laravel

来自分类Dev

Laravel基于文件的缓存的大小限制是多少?

来自分类Dev

如何清除Laravel Bootstrap缓存配置文件?

来自分类Dev

自定义路由文件上的Laravel路由缓存

来自分类Dev

如何获取laravel(文件)缓存的密钥过期时间?

来自分类Dev

如何获取laravel(文件)缓存的密钥过期时间?

来自分类Dev

自定义路由文件上的Laravel路由缓存

来自分类Dev

Laravel:对缓存文件夹使用绝对路径

来自分类Dev

如何在 Laravel 多租户中使用文件缓存