Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of suffix in sling URLs

Tags:

aem

sling

Sling provides a functionality to ease resource resolution. It's ability to resolve to exact resource representation we need is very useful in content based application.

However I am not able to understand one question is the use of suffix.

Example:

http://localhost:4502/content/app/mycomponent.large.html/something.html

Here, "something.html" is the suffix. I want to know under what circumstances would I go for a suffix ? What advantages do we get when compared to passing the information as a selector ?

like image 903
Prashant Onkar Avatar asked Dec 27 '16 13:12

Prashant Onkar


People also ask

What is Sling in AEM?

AEM is built using Sling, a Web application framework based on REST principles that provides easy development of content-oriented applications. Sling uses a JCR repository, such as Apache Jackrabbit, or in the case of AEM, the CRX Content Repository, as its data store.

What are AEM selectors?

A selector is a special form of parameter for the URL. Just like a query string, it is there to change the behaviour of a HTTP request/response based on parameter. These are mostly implementation dependant but the general convention is to interpret them based on location.


2 Answers

Pretty hard question, but I will try to clear up it a bit.

According to best practices, selectors should not be treated as input parameters in functions. It means, that you should use selectors only for registering servlets (or JSP file names) and selectors should notify sling about the operation you want to do with given resource or the way it should be displayed.

For example, let's imagine, that you have page /page/a.html and you have some special representation for mobile devices. Then, accessing it with /page/a.mobile.html will open this page in a mobile friendly way.

On the other hand, suffix usually used to provide additional information to your servlet/JSP page. Just check editor interface in TouchUI: the url looks like

localhost:4502/editor.html/content/pageYouEdit.html

So you always stays on the same page /editor.html, but suffix notifies Edit Interface which page to edit.

Also another example: there is a nice library for include content dynamically - https://github.com/Cognifide/Sling-Dynamic-Include. When it's configured for some component, then after the page is loaded, your component will be included with AJAX call, like this:

publish/pathToThePage/_jcr_content/pathToTheComponentNode.nocache.html//apps/pathToTheRenderer

In this example, you can see, that both selector and suffix is used. Selector tells, what is special about a representation of this component we need and suffix tells which component should render requested data.

like image 118
Oleksandr Tarasenko Avatar answered Jan 04 '23 17:01

Oleksandr Tarasenko


It's used to provide different versions of a resource, which are cacheable. This plays nicely with the Apache HTTP module known as "Dispatcher" which Adobe architects will recommend in any AEM implementation.

http://me.com/page.html/todays_promotion   <-- cacheable

http://me.com/page.html?todays_promotion   <-- not cacheable

The second example there, with a request parameter, should be treated as a variable resource that could produce different results upon each request.

like image 38
lance.dolan Avatar answered Jan 04 '23 17:01

lance.dolan