Where should the static resources such as CSS, JS, and images used by the website front-end be placed?

Calendar 👁️ 165

As an experienced website operation expert, I am well aware that the reasonable management of website front-end static resources is crucial for website performance, maintenance convenience, and even search engine optimization (SEO).AnQiCMS (AnQiCMS) took this into full consideration from the very beginning of system design, providing developers and operators with a clear and efficient path for resource management.

Today, let's delve into the discussion of where the CSS, JS, and images, etc., static resources used on the front end of your AnQiCMS website should be placed for the most reasonable and efficient practice.

The mystery of the static resource directory of AnQi CMS: Where should CSS, JS, and images live?

During the process of building and operating your Anqi CMS website, you may encounter a common question: Where should the front-end static files that constitute the visual skeleton (CSS), interaction logic (JavaScript), and rich content (images) of the website be stored in the system?Understanding this can not only make your website structure orderly, but also lay a solid foundation for the optimization of website performance and future expansion.

AnQi CMS was designed to provide an efficient, customizable, and easy-to-expand content management solution. It has planned a clear and professional 'home' for front-end static resources:/public/static/Directory.

This directory is the ideal destination for all the CSS, JavaScript, and design images (such as logos, background images, icons, etc.) that are directly managed and maintained by front-end developers.Let us explore how these resources should be properly placed.

CSS stylesheet: the foundation of a website's 'face value'

Your website's stylesheet (CSS file), which defines the color, layout, and fonts of the website, is a direct embodiment of its 'face value.' These files should be placed in the AnQi CMS./public/static/css/directory.

You can divide the folders further under thiscssdirectory, for example:

  • Create for different themestheme-name/css/Directory.
  • Create for specific functional modulesmodule-name/css/Directory.
  • Name the core style file directlystyle.cssPlace it incssUnder the root directory.

When referencing these styles in the template, it is strongly recommended to use the ones provided by Anqicms to maintain path flexibility and compatibilityTemplateUrlSystem variables. For example, you can introduce your main stylesheet like this:

<link href="{% system with name="TemplateUrl" %}/css/style.css" rel="stylesheet">

JavaScript script: the vitality source of the 'brain' of the website

JavaScript scripts are responsible for the dynamic interaction of websites, form validation, and various front-end effects. They are the vitality source of the 'brain' of the website. They should usually be placed in/public/static/js/directory.

Similarly, in order to maintain the readability and maintainability of the project, you canjscreate subfolders under the directory, for exampleplugins/used to store third-party libraries,custom/used to store the logic scripts you have written yourself.

It is still recommended to use when introducing JavaScript files in the templateTemplateUrl:

<script src="{% system with name='TemplateUrl' %}/js/main.js"></script>

The benefits of doing so are, even if your website migrates to a new domain or enables CDN,TemplateUrlCan also intelligently generate the correct resource path for you.

Images and other media files: visual aids for the 'content' of the website.

It is recommended to store images that constitute website design elements or serve as auxiliary content, such as logos, website icons (Favicon), page background images, button icons, and so on,/public/static/images/directory.

You can also create more specific subdirectories based on the purpose of the images, such asicons//backgrounds/etc., for better management and search.

When referencing these image resources in the template,TemplateUrlit is still your helpful assistant:

<img src="{% system with name='TemplateUrl' %}/images/logo.png" alt="网站Logo">

Why choose/public/static/the catalog?

This seemingly simple catalog structure actually contains the considerations of Anqi CMS in architectural design:

  1. Clear separation of responsibilities: /templateThe catalog focuses on storing HTML template files, while/public/static/it is specially designed for front-end static resources. This separation allows developers to focus more on their respective fields, reducing cross-interference.
  2. The root directory of the web server access: publicThe directory is usually configured as the root directory of the web server (such as Nginx, Apache). This means that all the files placed inpublicFiles under the directory can be accessed directly via URL, and/static/The existence of subdirectories further distinguishes the core files of the CMS system from front-end static resources, improving security and management efficiency.
  3. Beneficial for deployment and CDN acceleration:This structure is inherently beneficial for website deployment and CDN (Content Delivery Network) integration. The web server can directly transfer/public/The directory provides services to the outside, and CDN can also easily fetch and cache/public/static/The resources, thereby significantly improving the loading speed and user experience of the website
  4. Modularization and scalability:A clear directory structure facilitates team collaboration and project expansion. When new topics or functional modules need to be introduced, it is only necessary to follow the established norms in order tostaticCreate corresponding subdirectories under the catalog to maintain consistency.

In summary, follow the recommendations of Anqicms./public/static/The directory structure is used to manage your front-end static resources, not only is it an embodiment of code specification, but also a key step to achieve high-performance and high-maintainability websites.It makes front-end resource management simple and intuitive, allowing you to focus more on website content and feature innovation.


Frequently Asked Questions (FAQ)

  1. Question: Why is it/public/static/catalog instead of directly under/public/Where are the static resources stored?Answer: Place the static resources in/public/static/Below is a good practice, the main purpose is to separate responsibilities and make management clear.publicThe directory is the root directory that the web server serves to the outside, which may contain some dynamic content generated by CMS systems or uploaded by users (such as/uploads/directory). AndstaticThe subdirectory clearly indicates that it stores stable front-end static resources (CSS, JS, design images) maintained by developers.This distinction makes deployment, backup, permission management, and CDN configuration more flexible and secure.

  2. Ask: Should the images I upload through the media management function in the background (such as article illustrations, Banner images) also be placed/public/static/below?Answer: No, the images you upload through the AnQi CMS backend's media management function (such as uploading images when editing articles, setting Banner images, etc.) are usually automatically processed and stored in specific directories by the CMS system logic, such as/public/uploads/Or specify a path.These images are not manually placed by you, but are dynamically generated by CMS.You do not need to manually manage the physical location of these files, just refer to them in the template through the corresponding tags or variables, Anqi CMS will be responsible for providing the correct access path./public/static/The directory is mainly used to store static resources that are directly maintained by front-end developers, which are design-oriented and structural.

  3. Question:TemplateUrlWhat is the role of this template variable? Can I directly use relative paths to refer to resources?Answer:TemplateUrlIt is a system-level variable provided by Anqi CMS that dynamically generates the root path for static resources of the current website template. For example, it may resolve tohttp://yourdomain.com/template/defaultorhttp://yourcdn.com/template/defaultetc. It is strongly recommended to useTemplateUrlTo refer to static resources instead of using relative paths (such as/static/css/style.css)。The advantage of doing this is:

    • Multi-site compatibility:If your Anqi CMS is deployed with multiple sites, each site may have different domain names or template paths,TemplateUrlensuring the path is correct.
    • Environmental adaptability:Handle the path differences between development and production environments (may be deployed in different subdirectories or domains).
    • CDN Integration:Convenient for integrating CDN services in the future, just configure it in the background.TemplateUrlPoint to the CDN domain, all resource paths will be automatically updated without modifying the template file.
    • Using relative paths may cause resource loading failures in some complex deployments or multi-site modes.

Related articles

Where is the default directory for storing AnQiCMS template files?

## Unveiling the Location of AnQiCMS Template Files: Default Directory Depth Analysis When building and operating a website with AnQiCMS, template files are the core that determines the appearance and interaction of the website.Whether it is to carry out personalized customization, fault diagnosis, or secondary development, clearly understanding the storage location of the template files is the first step.Where is the default template file stored for AnQiCMS?The answer is the `/template` directory. ###

2025-11-06

How to quickly view the root directory path of the current AnQiCMS installation?

As an experienced website operations expert, I am well aware that clearly understanding the file structure and critical path of AnQiCMS website is of great importance when managing and maintaining it.Especially when adjusting configurations, modifying templates, troubleshooting, or managing multiple sites, quickly locating the root directory path of AnQiCMS can greatly enhance our work efficiency.AnQiCMS is a modern content management system developed based on the Go language, with flexible and diverse deployment methods, ranging from running directly on the server to managing through panels such as Baota, 1Panel, and containerized deployment

2025-11-06

Does the `exists -eq 0` check in the AnQiCMS `start.sh` script cause a race condition in extreme high concurrency startup scenarios?

As an experienced website operations expert, I deeply understand AnQiCMS' excellent performance in providing efficient content management solutions for small and medium-sized enterprises and self-media operators.It gained widespread praise for its high performance and many practical features brought by the Go language.However, even the most excellent system, its deployment and operation details are worth in-depth discussion.

2025-11-06

How to add a delay in the `start.sh` script of AnQiCMS to ensure that the port is completely released before starting?

## Ensure AnQiCMS graceful restart: Add a delay mechanism in the `start.sh` script AnQiCMS provides strong support for content operators with its efficient and concise features developed based on the Go language.Its deployment is simple and execution is fast, making content management and website operations smooth and easy.However, even such a high-performance system, in certain specific O&M scenarios, such as frequent restarts, updates and deployments, or when the server resources are tight, you may accidentally encounter a pesky problem: the program fails to start

2025-11-06

How to find and edit the template folder being used by the current site in AnQiCMS?

As an experienced website operations expert, I know that mastering the positioning and editing methods of templates like AnQiCMS, which is a flexible and efficient content management system, is a key step to achieving website personalization, enhancing user experience, and optimizing SEO.AnQiCMS with its lightweight and high-performance Go language provides us with a solid foundation, and its powerful template customization capabilities give content operators unlimited possibilities.Today, let's delve into how to accurately find and edit the template folder currently in use on the AnQiCMS website

2025-11-06

Under the multi-site management mode, how are the cache and independent directories of each site named?

As an experienced website operations expert, I have accumulated rich experience in managing and optimizing various websites, especially with a deep understanding of AnQiCMS (AnQiCMS) as an efficient and stable content management system.Multi-site management is a powerful feature of AnQiCMS, allowing users to easily operate multiple independent websites under a single system.However, under such a model, many operators may be curious: How is the cache and data directory of each site independently managed by the system, and how are they named?Today, let's delve deeply into this issue.

2025-11-06

What is the usual access path (URL) for the AnQiCMS backend? Can it be customized?

As an experienced website operations expert, I am well aware of the importance of the security and convenience of the background management entry for website operations.Understanding the backend access path settings and customization capabilities of AnQiCMS, an efficient and secure content management system, is an indispensable part of our daily work.Today, let us delve into the mysteries of the AnQiCMS backend access path together.

2025-11-06

Where is the default storage location for the executable files of the AnQiCMS project?

AnQi CMS is an efficient and customizable enterprise-level content management system, with its core being a lightweight and powerful executable file.For any website operator, it is crucial to know the location of this 'heart', as it not only concerns daily maintenance and management, but also affects the stable operation and fault troubleshooting of the system.Where is the executable file of the project carrying all the functions of AnQi CMS usually stored?Let's uncover this mystery.

2025-11-06