Assetic、图像资源和缓存

发布于 2025-01-03 21:00:54 字数 2151 浏览 3 评论 0原文

我正在努力将 Assetic 集成到我正在构建的应用程序中。该应用程序遵循 MVC 模式,但不使用任何框架。 Twig 用于模板化。

我已阅读文档并查看了一些 有帮助 博客文章

该应用程序的结构如下:

  • 应用程序
    • twig_templates
    • js
    • CSS
  • public_html
    • js
    • CSS
    • 图片

树枝模板被渲染,然后由应用程序返回,所以这非常简单。 application 文件夹下的 jscss 文件夹将保存原始 javascript 和 css 文件。

我的计划是,合并和缩小的 js 和 css 文件将存储在 public_html 文件夹下的 js 和 css 文件夹中。

由于我不打算使用 assetic 优化任何图像,因此它们将直接放置在 public_html 下的 images 文件夹中。

现在的问题是:

  • 我知道通过使用 twig 中的 assetic,组合和缩小的资源可以导出到我的 public_html 目录:

    {% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %}
        >
    {% endstylesheets %}
    

    在这种情况下,每次渲染模板时都会重新生成 css/all.css 文件吗?

  • 使应用程序可移植(可以使用虚拟主机托管,甚至可以在文件夹中托管)并确保在具有路由 URL(例如 http://site.com/controller/)的站点中正常工作操作,assetic是否提供将图像的URL“重写”为绝对URL(即images/a.jpghttp://mysite.com/images/a.jpg)?

  • 使用嵌套模板时 assetic 是否有效?

    parent.twig:

    ;
    
        <头>
            {% 区块头 %}
                
                {% block title %}{% endblock %} - 我的网页
            {% 末端嵌段 %}
        
        <正文>
        
    
    

    child.twig:

    {% 扩展“parent.twig” %}
    
    {% 块标题 %}索引{% endblock %}
    {% 区块头 %}
        {{ 父级() }}
        
    {% 末端嵌段 %}
    

    在这种情况下,我如何让 assetic 知道它应该结合 childstyle.cssmainstyle.css 并将其作为 1 个文件提供?

I am working on integrating Assetic into an application that I am building. The application follows the MVC pattern but does not use any frameworks. Twig is used for templating.

I have read the documentation and have looked at a few helpful blog posts.

The application is structured like this:

  • application
    • twig_templates
    • js
    • css
  • public_html
    • js
    • css
    • images

The twig templates are rendered and then returned by the application, so that is quite straight forward. The js and css folders underneath the application folder would hold the raw javascript and css files.

My plan is that combined and minified js and css files would be stored in the js and css folders under the public_html folder.

Since I don't plan to optimize any images using assetic, they will be placed in the images folder underneath public_html directly.

Now the question:

  • I understand that by using assetic from twig, combined and minified assets can be exported to my public_html directories:

    {% stylesheets '/path/to/sass/main.sass' filter='sass,?yui_css' output='css/all.css' %}
        <link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
    {% endstylesheets %}
    

    In this case is the css/all.css file regenerated everytime that template is rendered?

  • To make the application portable (it could be hosted using a virtual host, or perhaps even in a folder) and to ensure things work in a site with routed URLs like http://site.com/controller/action, does assetic provide anyway "rewrite" URLs for images into absolute ones (i.e. images/a.jpg into http://mysite.com/images/a.jpg)?

  • Does assetic work when using nested templates?

    parent.twig:

    <!DOCTYPE html>
    <html>
        <head>
            {% block head %}
                <link rel="stylesheet" href="mainstyle.css" />
                <title>{% block title %}{% endblock %} - My Webpage</title>
            {% endblock %}
        </head>
        <body>
        </body>
    </html>
    

    child.twig:

    {% extends "parent.twig" %}
    
    {% block title %}Index{% endblock %}
    {% block head %}
        {{ parent() }}
        <link rel="stylesheet" href="childstyle.css" />
    {% endblock %}
    

    In this case, how can I let assetic know that it should combine childstyle.css and mainstyle.css and serve it as 1 file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拔了角的鹿 2025-01-10 21:00:54

至于这个答案,不可能将从父级继承的样式表与子级的样式表结合起来
跨继承模板组合 Assetic 资源

as for this answer it is not possible to combine inherited stylesheets from parent with child's
Combining Assetic Resources across inherited templates

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文