How to automatically handle or manually set image lazy loading for document content in AnQiCMS to improve display performance?

Calendar 👁️ 72

In today's fast-paced online environment, website loading speed is crucial for user experience and search engine rankings.Images are often a major component of web content and can also be a key factor affecting page loading performance.To solve this problem, the Lazy Loading image technology emerged.AnQiCMS as an efficient content management system, provides us with flexible image optimization and lazy loading implementation solutions.

Understanding image lazy loading and its importance

Lazy loading of images, as the name implies, is to delay loading images on web pages.It does not download all images immediately when the page is first loaded, but only those that appear in the user's viewport (that is, the visible area on the screen).When the user scrolls the page, new images will enter the viewport before they are loaded.

This loading strategy brings significant benefits:

  • Improve the speed of the first screen load:Reduced the amount of data requests during the first load, allowing users to see the page content faster.
  • Save bandwidth resources:Avoided loading images that the user may never see, thereby reducing bandwidth consumption on the server and the user's end.
  • Improve user experience:The page response is faster, reducing the user's waiting time, especially for mobile device users.
  • Beneficial for SEO:Search engines are increasingly focusing on page loading speed, lazy loading can help improve the Core Web Vitals score of a website, which may lead to better search rankings.

AnQiCMS as a platform committed to providing efficient and customizable solutions naturally also considers the impact of image optimization on the overall performance of the website.

AnQiCMS image processing strategy overview

Before delving into lazy loading, it is worth mentioning that AnQiCMS itself provides a variety of image optimization features, which complement lazy loading and help improve website performance. We can find these options in the "Content Settings" panel:

  • Remote Image Download:If the content refers to an external link image, the system can choose to download it to the local server for unified management and optimization.
  • WebP image format conversion:WebP is a modern image format that is usually much smaller than JPEG and PNG files and can maintain high quality.AnQiCMS supports automatic conversion of uploaded images to WebP format, significantly reducing the size of the images.
  • Automatically compress large images:For images that are too large, the system can automatically compress them, specifying the maximum width after compression, which helps reduce the file size of the image and accelerate the transmission speed.
  • Flexible thumbnail processing:We can set the thumbnail size and processing method (such as proportional scaling based on the longest edge, cropping based on the shortest edge, etc.) to meet the needs of different page layouts and avoid loading the original large image on the list page.In addition, the system also supports batch regeneration of thumbnails, which is convenient for adjusting and optimizing strategies.

These built-in image processing functions provide high-quality, small-volume image sources for lazy loading, making the lazy loading effect better.

Implement image lazy loading: core method

AnQiCMS through its powerful template system provides a flexible implementation for lazy loading of images in document content.Although it does not have a global 'one-click enable' switch, it allows us to easily implement image lazy loading effects by using template tags during content rendering.

Manually set (template level)

The lazy loading of images in the AnQiCMS document mainly involves modifying the template. When we edit articles or product content in the background, the images we insert will eventually be loaded througharchiveDetailThis tag is used to render and display. This tag provides alazyattribute, specifically used for integrating lazy loading of images.

For example, using the document content,tag-/anqiapi-archive/142.htmlThe document explains in detail.ContentThe field calling method should be specified:

The Content field supports lazyload for images. It needs to be usedlazy="{定义的src名}"Process, for example, if you use the lazyload plugin you need to<img src="" />to<img data-src="" />call it like thislazy="data-src"

This means that AnQiCMS can recognize and convert the attributes of image tags when rendering document content. Suppose we choose a common front-end lazy loading JavaScript library, such asLazysizesIt usually will display the image'ssrcattribute is replaced withdata-srcand when the image enters the viewport it willdata-srcAssign the value againsrc.

Therefore, in our template (for exampledetail.htmlorarchive/detail.html) when rendering the document content, we can set it like this:

{# 假设archiveContent变量存储了文档的HTML内容 #}
<div>
    {%- archiveDetail archiveContent with name="Content" lazy="data-src" %}
    {{archiveContent|safe}}
</div>

Here:

  • {% archiveDetail archiveContent with name="Content" ... %}: Is used by AnQiCMS to obtain documentsContentfield content label.
  • lazy="data-src": This is the key. It tells AnQiCMS, during renderingContentall in the field<img>when the tag is rendered,srcthe value of the properties is transferred todata-srcThe attribute contains, and sets the originalsrcThe attribute is set to empty or a placeholder (the specific behavior depends on the CMS implementation, but the purpose is to not load the image immediately).
  • {{archiveContent|safe}}:|safeThe filter is crucial, it ensures thatarchiveContentThe HTML content contained is not escaped but is output as raw HTML to the page so that the browser and front-end JavaScript libraries can parse and handle it correctly.

Combine with front-end JavaScript library

Only set in the templatelazy="data-src"It is not enough to implement lazy loading. This only changes the HTML structure of the image. The browser does not know.data-srcThe meaning. We need a frontend JavaScript library to listen for page scroll events, determine if an image is in the viewport, and based on that, assigndata-srcthe content back.srcThus, it triggers image loading.

There are common lazy loading libraries:

  • Lazysizes:Powerful, easy to integrate, and supports responsive images.
  • lozad.js:Lightweight, using Intersection Observer API, excellent performance.
  • Native Lazy Loading:Modern browsers (Chrome, Firefox, etc.) already support it nativelyloading="lazy"Properties. If only the users who support these browsers are considered, the AnQiCMS can be used directly.lazyproperties toloading="lazy".

To integrate these libraries, it usually only needs to be added to the page.<head>or<body>Add the corresponding JS file at the bottom of the tag. For example, using Lazysizes:

<script src="path/to/lazysizes.min.js" async=""></script>

Or, if AnQiCMS'slazyproperty supports it directlyloading="lazy"And your target browser supports native lazy loading, you even don't need any additional JS library.

Optimization Practices and Suggestions

  1. Choose the appropriate lazy loading scheme:Consider your website audience and browser compatibility needs. For most modern websites, it is advisable to prioritize nativeloading="lazy"Property. If you need broader compatibility and advanced features (such as preloading, responsive images, etc.), choose a mature JS library.
  2. Test and verification:After deploying lazy loading, it is necessary to test on different devices and browsers to ensure that images can be loaded normally and the lazy loading effect meets expectations.Check the network request to confirm that the image is loaded only when it scrolls into the viewport.
  3. Combine AnQiCMS image optimization feature:Lazy loading is not万能。It solves the problem of “when to load”,but “what to load” is also important.Be sure to combine the AnQiCMS backend's WebP conversion, image compression, and thumbnail generation functions to ensure that the loaded images are optimized, with small file sizes and high quality.
  4. Provide placeholder or background color:Before the image is loaded, the page may appear blank or have jumping content. You can set a background color placeholder for the image using CSS, or use a very small blurred image assrcPlaceholder to smooth user experience.
  5. Note the first screen image:Images within the first screen (the area that users can see without scrolling) are usually not recommended for lazy loading, as they are the first content that users see and should be loaded as soon as possible.Lazy loading should mainly be applied to the content below the first screen.

By flexible application

Related articles

How to optimize page titles and descriptions for search engine results using advanced SEO tools (TDK, standard links)?

In website operation, it is crucial to make your content stand out on search engine result pages (SERP) and attract targeted users to click.This not only concerns website traffic, but also directly affects brand exposure and business conversion.AnQiCMS (AnQiCMS) understands this need and provides you with a series of advanced SEO tools to help you refine the optimization of page titles, descriptions (TDK), and standard links, thereby enhancing the search engine visibility of your website.### The Foundation for Improving Search Engine Visibility: The Refinement of TDK Settings TDK

2025-11-09

How to control the special display of content on the homepage or other blocks (such as headlines, sliders)?

In website operation, we often need to make certain important content stand out on the homepage or in specific areas to attract the attention of visitors, such as the latest headline news, exquisite product slides, or urgent notification announcements.AnQiCMS provides a very intuitive and efficient mechanism to handle this requirement, that is, 'recommended attributes'.### What is the recommendation attribute?\n\nIn AnQiCMS, the recommendation attribute is like a "tag" for content, where you can mark articles, products, events, and other content with specific tags to tell the system how they should be treated differently

2025-11-09

How to set the document title, introduction, thumbnail, and optimize its display effect on the list and detail pages?

AnQiCMS provides a comprehensive mechanism to help us manage the title, summary, and thumbnail of website content in detail.These elements are not only the foundation for content display, but also the key to improving user experience and SEO optimization (SEO).Set and optimize their display on list and detail pages to make our website content more attractive and easier for search engines to crawl and understand.### Basic backend settings: Make content information clear and accurate In the AnQiCMS backend, whether it is to publish articles, products, or create single pages

2025-11-09

How does the adaptive, code adaptation, and PC + mobile independent site mode affect the display compatibility of front-end content?

In website operation, ensuring that your content displays perfectly on various devices is the key to improving user experience and SEO effectiveness.AnQiCMS (AnQiCMS) provides three flexible mode options for displaying front-end content compatibility: adaptive, code adaptation, and PC + mobile independent site mode.Understanding how these patterns work and their impact on the display of your front-end content can help you better plan and manage your website.### One, Adaptive Mode: Single Template, Smooth Experience on Multiple Devices Adaptive mode, as the name implies

2025-11-09

How to optimize front-end loading and display by converting and automatically compressing images within the site to Webp format?

Optimize the website front-end loading and display, images are one of the key links.For us who pursue efficiency and a good user experience, it is crucial to properly handle the images on the site.The AnQiCMS (AnQiCMS) provides very practical functions in this aspect, through WebP format conversion and automatic compression, we can significantly improve the loading speed and image display effect of the website.We all know that large image files are a common cause of slow website loading.This will not only affect the user experience and increase the bounce rate, but also have a negative impact on search engine optimization (SEO)

2025-11-09

How different thumbnail processing methods (aspect ratio scaling, padding, cropping) affect the display effect of images on the front-end?

In website operation, images play a vital role, especially in places like list pages and detail pages where thumbnails are displayed. They not only affect the beauty of the page but also directly relate to the click-through rate and reading experience of users.AnQiCMS (AnQiCMS) offers various flexible thumbnail processing methods to help users meet the needs of image display in different scenarios.Understanding how these methods - scaling, padding, and cropping - affect the final presentation of images on the front end is particularly important for optimizing the visual experience of a website.Why is thumbnail processing so crucial

2025-11-09

How to set a default thumbnail to ensure that documents without uploaded images also have a unified display?

When using AnQi CMS to manage website content, we often encounter such situations: some articles, products, or pages may not have uploaded exclusive thumbnails due to insufficient content or oversight.This not only makes the website page look unprofessional and inconsistent, but may also affect users' desire to click on the content.Luckyly, Anqi CMS provides a very practical feature that can solve this problem once and for all - that is, setting a default thumbnail to ensure that even documents that do not upload pictures separately can have a unified and beautiful display effect.Why is it necessary to set a default thumbnail

2025-11-09

How to display the document Tag label on the front-end page and use it as an entry for content association?

In modern website operations, how to effectively organize and present content is not only related to user experience, but also a key aspect of Search Engine Optimization (SEO).AnQiCMS (AnQiCMS) provides a powerful and flexible Tag label feature, which not only helps you better manage website content but also serves as a convenient entry point for users to find related information, greatly enhancing the association of content and the interactivity of the website. ### Overview of Tag Labels in AnQi CMS The design philosophy of Tag labels in AnQi CMS is very open and flexible.They are different from the traditional classification system

2025-11-09