Use the SymfonyAsset component to manage your CSSJavascript and image files

Source: Internet
Author: User
The reason why I want to introduce the Symfony Asset component by using the SymfonyAsset component to manage your CSSJavascript and image files is that I guess this component is one of the most vulnerable components in the Symfony component package. I have never been familiar with relevant documents or functions before. I didn't remember such a thing until recently when my company's website was about to accelerate CDN.

Many of you may have seen the twig function asset in the official Symfony best practice tutorial. However, the document does not explain what asset is doing and what benefits it brings. I have recently carefully read the document of the Asset component, made some practices, and shared some useful information.

What is Asset?

In fact, they are collectively referred to as static files such as css/javascript/images.

FAQs about Asset management and maintenance

In the past, the paths of static files were stored in template files. for example, the official website provides an example:

  
   
 

Unless it is a very simple project, you can write it like this. you 'd better not write these paths to death, because you will dig the following pitfalls for yourself:

  1. You need to constantly write the full path in every place where the static file is referenced.
  2. Version Management is troublesome. You may want to cache your static files, but the cached static files need to be added after the URL address (generally similar to/main.css? V = 1) to control whether the cache is to be updated, but if your path is written to an infinite number of files ...... Then you can change it one by one, which is easy to leak.
  3. At the beginning of the project, it was a good job to write the static file path. in case the path of the static file directory changes, you will be stupid. let's change it one by one.
  4. There is a technology called multi-CDN, which is used to reduce the pressure on a single CDN. If the file main.css is configured with two CDNs: http://cdn1.com/main.cssand http://cdn2.com/main.css, if the content is written to the dead, how can you enable the webpage to return one of the two CDN addresses?
What can the Symfony Asset component do?

Exactly corresponds to the above issues:

  1. With it, you don't have to write all the paths, but you can omit the public directories.
  2. With it, it is convenient to specify the static file version!
  3. With it, the location of the mobile static file is convenient. if you change the directory to the domain name to the CDN, you can change it as needed!
  4. With it, implementing multiple CDNs is not a dream!

Let me write it here today. If you are from non-my personal website (http://chrisyue.com) to see the reprint, please click the original text to see whether the follow-up is complete.

How can I use the Symfony Asset component? I am using the Symfony framework. how can I use the Symfony Asset component in the framework? Weak: What is the Symfony Assetic component? is it related to the Asset component?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.