To access a specific page directly from the publish instance without using the dispatcher | Community
Skip to main content
Community Advisor
January 3, 2024
Solved

To access a specific page directly from the publish instance without using the dispatcher

  • January 3, 2024
  • 5 replies
  • 827 views

Hi All

 

We need to access a specific page directly from the publish instance without using the dispatcher, while allowing other pages to continue being served through the dispatcher.
How to do that ? can you anyone pls provide details ..

 

Thanks 

Kannan

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 TarunKumar

Hi @knan ,

You can achieve this in multiple ways:
     

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • Request URI contains a question mark (?).

    • Indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.

    • The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (configurable).

  • If the AEM instance responds with the following headers:

    • no-cache
    • no-store
    • must-revalidate

      If you want handle this through AEM backend then below are the 2 options.

      1. At component level component model class.

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class Component{

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       

      2. At page level, now you can call this page in body html based on some condition:

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class PageMOdel {

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       


      Thanks
      Tarun

 

5 replies

Level 4
January 3, 2024

Hello

you can access a specific page directly from the publish instance, you can directly use the publish instance URL followed by the page's path. but generally bypassing the dispatcher isn't usually recommended for a production environment for multiple reasons like Caching and Load Balancing etc.

if you still want to access the specific page you can try the below approach 

http://<publish-server-ip>:<port>/content/project/test.html

Replace <publish-server-ip> and <port> with the IP and port number for your publish instance.

 

Thanks,

Venkat

Madhur-Madan
Community Advisor
Community Advisor
January 3, 2024

Hi @knan ,

To bypass a specific page from dispatcher you can do the following.
I am assuming the page to bypass is '/content/myProject/us/en/home'

APPROACH 1
1. Access your dispatcher configuration file (often named dispatcher.any).
2. Add a rule to exclude caching for the specific page. This prevents the dispatcher from intercepting requests for this page.
/excludePage
{
         /glob "/content/myProject/us/en/home"
}
/excludePage: This directive is used to define URLs that should be excluded from the dispatcher.

APPROACH 2
You can set up a rule within the /filter section to bypass the dispatcher for a particular URL.
/filter
{
    /0001
    {
        /glob "/content/myProject/us/en/home*"
        /type "deny"
     }
}


Thanks

TarunKumar
Community Advisor
TarunKumarCommunity AdvisorAccepted solution
Community Advisor
January 3, 2024

Hi @knan ,

You can achieve this in multiple ways:
     

The /rules property controls which documents are cached according to the document path. Regardless of the /rules property, Dispatcher never caches a document in the following circumstances:

  • Request URI contains a question mark (?).

    • Indicates a dynamic page, such as a search result that does not need to be cached.
  • The file extension is missing.

    • The web server needs the extension to determine the document type (the MIME-type).
  • The authentication header is set (configurable).

  • If the AEM instance responds with the following headers:

    • no-cache
    • no-store
    • must-revalidate

      If you want handle this through AEM backend then below are the 2 options.

      1. At component level component model class.

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class Component{

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       

      2. At page level, now you can call this page in body html based on some condition:

      @Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)
      public class PageMOdel {

      @Inject
      private SlingHttpServletResponse response;

      @PostConstruct
      protected void init() {
      response.setHeader("Dispatcher", "no-cache");
      }
      }

       


      Thanks
      Tarun

 

JakeCham
Level 6
January 3, 2024

Hi @knan ,

 

I think you can use ignoreUrlParams which helps to by pass the despatcher cache.

 

/ignoreUrlParams

{

  /001{ /glob "*" /type "allow"}

  /002 { /glob "specific page ID" /type "deny"}

}

 

with above rule, URL having that specific page ID always fetches the latest content from the AEM instance.

kautuk_sahni
Community Manager
Community Manager
January 8, 2024

@knan Did you find the suggestions from users helpful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. If you have found out solution yourself, please share it with the community.

Kautuk Sahni