How to get page size information. | Community
Skip to main content
Level 2
April 27, 2023
Solved

How to get page size information.

  • April 27, 2023
  • 4 replies
  • 1310 views

Hi All,

 

I am trying to get page size information in AEM, but cannot locate it. Can you tell from where I can get this information.

 

Thank you.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shiv_Prakash_Patel

Hi @muskan_mala ,

You can get the page size from input stream as belows.

public long getPageSize(Page page) {
Resource contentResource = page.getContentResource();
InputStream contentStream = contentResource.adaptTo(InputStream.class);
return contentStream != null ? contentStream.available() : 0;
}

Here, getPageSize() method takes a AEM Page object as its argument, and returns the size of the page's content in bytes.

Hope this could help you!

Regards

Shiv

4 replies

AsifChowdhury
Community Advisor
Community Advisor
April 27, 2023

Hello @muskan_mala 

Please give more context on what you want to achieve.

 

If you are looking for the size or length of metadata of your targeted page then you can get it programmatically using Java in this way

 

import com.day.cq.wcm.api.Page; import com.day.cq.wcm.api.PageManager; import org.apache.sling.api.resource.ResourceResolver; ResourceResolver resourceResolver = slingRequest.getResourceResolver(); PageManager pageManager = resourceResolver.adaptTo(PageManager.class); Page targetedPage = pageManager.getPage("/content/mysite/homepage"); long pageSize = targetedPage.getContentResource().getResourceMetadata().getContentLength();

 

Thanks.

AsifChowdhury
Community Advisor
Community Advisor
April 27, 2023

Hello @muskan_mala 

You can also get page information in this way

import org.apache.sling.api.resource.ResourceResolver; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ValueMap; ResourceResolver resourceResolver = slingRequest.getResourceResolver(); Resource contentResource = resourceResolver.getResource(page.getPath() + "/jcr:content"); ValueMap valueMap = contentResource.adaptTo(ValueMap.class); long pageSize = valueMap.get("jcr:data", byte[].class).length;
milind_bachani
Adobe Employee
Adobe Employee
April 27, 2023

Hi @muskan_mala ,

Can you please share for what use-case you want to fetch the page-size ?

Best Regards,

Milind Bachani

Shiv_Prakash_Patel
Community Advisor
Shiv_Prakash_PatelCommunity AdvisorAccepted solution
Community Advisor
April 27, 2023

Hi @muskan_mala ,

You can get the page size from input stream as belows.

public long getPageSize(Page page) {
Resource contentResource = page.getContentResource();
InputStream contentStream = contentResource.adaptTo(InputStream.class);
return contentStream != null ? contentStream.available() : 0;
}

Here, getPageSize() method takes a AEM Page object as its argument, and returns the size of the page's content in bytes.

Hope this could help you!

Regards

Shiv

Shiv Prakash
joerghoh
Adobe Employee
Adobe Employee
May 1, 2023

This will only return the size of the jcr:content node in bytes, but that does not reflect the size of the rendered page.

Actually the size is only known when the complete page has been rendered. To have that information server-side, you would need to do a dummy-render process to have that information. In the browser it's probably much easier to achieve (you would only need to get the size of the HTML document).