In website operation, the loading speed of image content is crucial for user experience and Search Engine Optimization (SEO).Especially when an article contains a large number of images, if all the images are loaded at once when the page is loaded, it may cause the page to respond slowly, even affecting the patience of the user.To solve this problem, the image lazy loading (Lazyload) technology was born.

AnQiCMS as an efficient enterprise-level content management system, fully considers the flexibility of content publishing and website performance optimization, and provides a concise and powerful support for lazy loading of images in article content.

Why is image lazy loading so important?

Imagine, when a user visits a long article, the page is densely packed with dozens of high-definition images.If lazy loading is not used, the browser will try to download all images immediately, which will consume a lot of bandwidth and server resources and significantly extend the time it takes to render the page for the first time.The result is that users may lose patience before the page is fully loaded, or feel frustrated due to the long waiting time.

The lazy loading image technology can effectively solve this pain point. Its core idea is: only load the images within the visible area of the user, and for the images outside the screen that are temporarily not visible, they will be loaded when the user scrolls to their vicinity.This has several obvious benefits:

  1. Improve page loading speed:Reduced the amount of data requests during the first load, allowing page content to be displayed to the user more quickly.
  2. Save bandwidth and server resources:Avoid unnecessary image downloads, especially those that users may never scroll to.
  3. Improve user experience:Users do not have to wait long, they can see the page content faster, which improves the smoothness and response speed of the website.
  4. Beneficial for SEO:Search engines are increasingly emphasizing the loading speed and user experience of websites, lazy loading can help improve these indicators, and thus may lead to better search rankings.

How AnQiCMS handles and displays image lazy loading: Core mechanism

AnQiCMS handles image lazy loading in article content with a highly flexible and easy-to-integrate mechanism.It mainly prepares the HTML structure supported by lazy loading through template tags and specific parameters.

When you usearchiveDetailtag to retrieve and display articlesContentfield, AnQiCMS allows you to use a speciallazyParameters to indicate that the system generates HTML for lazy-loaded images. For example, if you want to place the image path in a name such asdata-srcIn the attribute, so that the front-end JavaScript library can recognize, you can use it like this:

{# 在您的文章详情模板中 (例如:template/{模型table}/detail.html) #}
<div>
    {# archiveDetail 标签用于获取文章详情,name="Content" 指定获取文章内容 #}
    {# lazy="data-src" 参数告诉 AnQiCMS 将图片URL放置到 data-src 属性中 #}
    {% archiveDetail articleContent with name="Content" lazy="data-src" %}
    {{ articleContent|safe }}
</div>

Here, lazy="data-src"This parameter is critical. When AnQiCMS rendersContentfields in<img>When labeling, it does not directly put the image path intosrcthe attribute, but transfers it todata-srcthe attribute. At the same time,srcThe attribute can be set to a placeholder (such as a very small gray image) or left blank.

In this way, the browser will only loadsrcThe content in the attribute (if any), and a large number of images outside the screen will be stored due to their actual pathsdata-srcLoading images lazily. When the user scrolls the page, these images enter the visible area, and the pre-integrated front-end JavaScript lazy loading library will detect thisdata-srcThe property, and assign the actual image path stored in it tosrcAttribute, thus triggering the actual loading of the image.

{{ articleContent|safe }}Here|safeThe filter is also very important, it tells AnQiCMS not to escape HTML tags in the article content, ensuring that the images, links, and other HTML structures included in the article can be rendered correctly.

Collaboration with image optimization features

In addition to providing lazy loading structure support, AnQiCMS also provides a series of powerful image optimization tools in the "Content Settings" section of the backend, which work in conjunction with lazy loading to further improve website performance:

  • WebP image format conversion:You can choose to enable the WebP image format. The WebP format usually has a higher compression rate than traditional JPEG and PNG formats, significantly reducing file size while maintaining image quality.Combine lazy loading, it can further reduce loading time.
  • Automatically compress large images:AnQiCMS can automatically compress large images uploaded by users to the specified width, which can effectively reduce the physical size and file size of the images, improving loading efficiency.
  • Thumbnail processing method and size settings:The system supports various thumbnail processing methods (such as proportional scaling by the longest side, cropping by the shortest side, etc.) and custom dimensions.This ensures that smaller, more suitable images are loaded in the article list or thumbnail display area, rather than the original large image.

These background optimization features combined with the front-end lazy loading mechanism together constitute the complete image content optimization solution of AnQiCMS, fundamentally improving the website's loading speed and user experience.

Summary

AnQiCMS provides a solid foundation for lazy loading of images in article content. It is responsible for preparing the backend HTML structure, placing the real path of the image todata-srcIn custom properties, while the actual loading logic is left to the front-end JavaScript library to handle.This front-end and back-end separation collaboration mode gives content operators great flexibility, allowing them to choose the most suitable front-end lazy loading solution according to their own website needs.At the same time, combined with the built-in image optimization tool of AnQiCMS, you can easily create a fast-loading, user-friendly, and search engine friendly high-performance website.


Frequently Asked Questions (FAQ)

1. Does AnQiCMS's lazy loading feature require an additional plugin to be installed?

AnQiCMS inherently supports image lazy loading structures at the template level. You do not need to install additional backend plugins. It generates with thearchiveDetailUsed in tagslazyparameter to create withdata-srcThe HTML property. However, the actual JavaScript logic that triggers image loading needs to be integrated into your frontend template manually, which is usually done by introducing a lightweight frontend lazy loading library or writing a small amount of JavaScript code.

2. Why did I setlazy="data-src"But the images are still loaded all at once?

This is likely because you are missing the corresponding JavaScript code to handle it on the front enddata-srcProperty. AnQiCMS is only responsible for inserting the image URLdata-srcHowever, the browser does not recognize this attribute and will not automatically perform lazy loading. You need to introduce a front-end lazy loading library (such aslazysizes.jsListen or yourself write JavaScript code to listendata-srcAttribute and assign its value when the image enters the visible areasrcProperty.

3. Does lazy loading support article thumbnails or images on list pages?

AnQiCMS is mainly for article detail contentContentImages provided in the fieldlazySupport for parameters. For article thumbnails (Thumb/LogoField), usually these images are directly displayed on the list page, and the quantity is relatively small, the system will optimize through the thumbnail processing and automatic compression functions in the background "Content Settings". If it is indeed necessary to implement lazy loading for thumbnails on the list page, then it is necessary to modify the template in order to<img>Manually add tagsdata-srcProperties, and implement with a front-end JS library.