Combining the design philosophy and features of AnQiCMS, we can clearly answer: AnQiCMS supports asynchronous loading of statistical codes through its flexible tags and high-performance architecture, and encourages users to adopt this optimization strategy.

AnQiCMS how to handle statistical code: core mechanism

AnQiCMS provides a special mechanism for inserting statistical code or JS auto-submit scripts, which is reflected inpluginJsCodeThe use of labels (such as documentstag-tongji.mdas shown). After we configure the automatic submission code for platforms like 360, Toutiao, etc., this code will be encapsulated and through{{- pluginJsCode|safe }}This tag is inserted into the front-end page.

The essence of this tag is to provide ainsertion point,一个允许我们将外部JavaScript代码无缝嵌入到我们网站模板中的位置。AnQiCMS本身作为一个内容管理系统,并不会直接“异步加载”这段代码,而是提供了一个让这段代码能够Using its specified wayEnvironment loaded (including asynchronous way).

The implementation principle of asynchronous loading: not just CMS

Can the statistical code be implemented asynchronously, mainly depending on the following aspects:

  1. Properties of the statistical code itself:Most mainstream statistical services (such as Google Analytics, Baidu Statistics) provide official code snippets that already containasyncordefersuch HTML attributes.

    • async属性:告诉浏览器可以异步加载脚本,即在下载脚本的同时继续解析HTML,脚本下载完成后立即执行,不保证执行顺序。 属性:Tell the browser to load scripts asynchronously, that is, continue parsing HTML while downloading scripts, and execute the scripts immediately after they are downloaded without guaranteeing the execution order.
    • defer属性:Also tells the browser to asynchronously load scripts, but the scripts will only be executed after the HTML document is fully parsed, and maintain the execution order of the scripts. When these containingasyncordeferThe code of the property is processed through AnQiCMS.pluginJsCodeWhen the label is** entered into the page, the browser will decide when to load and execute these properties to avoid blocking the rendering of the page.
  2. AnQiCMS's high-performance architecture:AnQiCMS is developed based on Go language, fully utilizing Goroutine to achieve asynchronous processing, and its system architecture itself emphasizes high concurrency and performance.This means that AnQiCMS is very efficient in processing page requests and generating content, and its internal mechanism does not add extra load to page loading due to the logic processing of the CMS itself.It provides a "lightweight" stage for loading external scripts, ensuring it does not become a bottleneck.

  3. Flexibility in placement:AlthoughpluginJsCodeTags provide insertion points, but as users, we usually place the statistical code on the page,<head>Label within (withasyncordeferproperties), or</body>before the end tag. Both of these placement methods help with non-blocking loading. Place in<head>and useasync/deferCan start downloading early without blocking the page rendering; placed in</body>Ensure that the page content is loaded before loading, which is also non-blocking by nature.AnQiCMS as a modern CMS, its template system allows us to flexibly control the final output position of these codes.

The impact on website speed and user experience

Adopting asynchronous loading statistics code strategy has a significant positive impact on website loading speed and user experience:

  • Reducing rendering blocking:Avoided blocking HTML parsing and page rendering by statistical code during download and execution, allowing users to see the page content faster.
  • Enhanced user perceived speed:Even if the script is loaded in the background, users will feel that the website is
  • Optimize SEO performance:Page loading speed is one of the important ranking factors for search engines, asynchronous loading helps improve the SEO performance of the website.


Common Questions (FAQ)

Q1: If the statistical code snippet I receive from the statistical service provider does notasyncordeferhave the property, what should I do?A1: Most modern statistical service providers will default to providing code that includes these properties. If your code snippet does not, you can try adding them manuallyasyncordeferproperties to<script>Tag in.However, **the recommended non-blocking loading method is to consult the official documentation of the statistical service provider.</body>Before the end tag, it can also greatly reduce the blocking of the initial rendering of the page.

Q2: In AnQiCMS templates, which position is the most suitable to insert the statistics code?A2: It depends on whether the statistics code you use containsasyncordeferproperties.

  • if it containsasyncordeferEnglish::can be placed in<head>English:At the end of the tag, this can start downloading the script as soon as possible without blocking the page content.
  • English:If not includedasyncordeferEnglish: To minimize the blocking of page rendering as much as possible, it is recommended to place the statistical code on</body>Before the end tag. This ensures that the HTML content and CSS styles have been loaded and rendered, and the user can see the complete page before the statistics script begins to load.

Q3: AnQiCMS based on Go language and Goroutine's asynchronous processing capability, does it directly mean that the front-end statistical code will be automatically loaded asynchronously?A3: AnQiCMS's Go language backend and Goroutine's asynchronous processing is mainly reflected in the efficient and non-blocking server-side handling logic.This means that AnQiCMS generates and returns page content very quickly and will not be delayed due to the processing of the CMS itself.However, the 'asynchronous loading' of front-end statistical codes more often refers to how the browser downloads and executes this JavaScript code on the client side.MechanismBut the specific asynchronous behavior (such as whether to block HTML parsing, execution order, etc.) is mainly determined by the statistical code itself.async/deferThe attribute and how browsers implement these attributes determine it.AnQiCMS backend performance provides a good foundation for the non-blocking loading of front-end scripts, ensuring that no additional delay is introduced on the server side.