Where should the static resources such as images, JS, and CSS used in the template be stored?

Hello!As a senior security CMS operator, I fully understand the importance of static resource management in website construction and content management.High-quality static resource management can not only improve website performance but also optimize maintenance efficiency.According to the document of AnQi CMS and our actual operation experience, this section elaborates in detail where the static resources such as images, JS, and CSS used in the template should be stored.

Unified specification for storing static resources in Anqi CMS

In the Anqi CMS, to achieve an efficient, customizable and easy-to-maintain content management, the project has clear specifications for the storage of static resources. According to the system design conventions, all style files (CSS), JavaScript scripts (JS), and images, etc. used in all templates should be uniformly stored in a designated directory, which is/public/static/.

These static resources are stored in one place,/public/static/under the directory, which is the core strategy for implementing unified resource management in the security CMS. This approach will store template files (usually stored in/templateThe content under the directory is clearly separated from the static resources they depend on.This structure not only helps to keep the project files tidy and organized, but also brings many conveniences to the subsequent optimization and maintenance work of the website.

This means that, regardless of which set of templates your website uses, or if you are developing a new template, all common resources, or even those used by specific templates, should be aggregated./public/static/The directory. For example, the global CSS style file of your website.global.cssCommonly used JavaScript librariesjquery.min.jsOr the website's logo imagelogo.pngAll, it is recommended to place them in this unified static resource directory.

In actual operation, in order to further refine management, you can/public/static/Create more specific subdirectories under the catalog to organize different types of resources. For example, put all CSS files into/public/static/css/the directory, and put JavaScript files into/public/static/js/Index, place image files here/public/static/images/Index. This hierarchical organization method helps you find and manage specific types of static resources faster, and maintain the clarity of the project structure.

Of course, AnQi CMS also providesTemplateUrlThis system tag allows you to reference resources within the currently active template directory.This is usually used to manage those unique styles or scripts that are closely associated with a specific template theme and are not intended to be shared with other templates./public/static/The catalog is still the preferred centralized storage point for all template static resources, providing the core entry and management foundation for the entire website's static resources.Follow this convention, it can ensure that your security CMS website achieves a better state in terms of performance, maintainability, and scalability.

Common Questions and Answers (FAQ)

1. Why does AnQi CMS recommend storing static resources in/public/static/the directory, rather than directly in the template directory?

This strategy of separating storage is adopted by Anqi CMS, mainly to achieve "separation of duties" and "unified management".Separating template files from static resources can make the project structure clearer and improve development and maintenance efficiency./public/static/The catalog focuses on providing cacheable static files.This separation also helps with performance optimization in the future, such as by accelerating static resources through CDN, or by not needing to process a large number of static files at the same time when updating templates.

2. Can I access the global configuration information of the site?/public/static/Do I create a sub-folder under the directory to organize my static resources?

Yes, it is strongly recommended that you in/public/static/Create logical subfolders under the directory to better organize your static resources. For example, you can create/public/static/css///public/static/js/and/public/static/images/The directory structure is as follows, so that different types of static files can be classified and stored. This organization method helps improve the findability and management efficiency of resources, especially when the project scale increases.

3. How should I reference the static resources stored in/public/static/the directory?

In your safe CMS template, you can directly use relative paths or absolute paths to reference stored in/public/static/The static resources under the directory. The most recommended way is to use relative paths starting with the root directory. For example, if your CSS file is located/public/static/css/style.css, you can use it in the template.<link rel="stylesheet" href="/static/css/style.css">Reference is performed. For images and JavaScript files, the reference method is similar, such as<img src="/static/images/logo.png">and<script src="/static/js/main.js"></script>.