What is the use of suffix in sling URLs
Asked Answered
W

2

6

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 ?

Welladvised answered 27/12, 2016 at 13:6 Comment(0)
S
9

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.

Shutt answered 27/12, 2016 at 18:31 Comment(0)
F
4

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.

Fibre answered 5/1, 2017 at 23:44 Comment(2)
as far as I know there is a problem with caching URL's with suffix, you have do some tricks to make it cacheable. Here you can find more details one-inside.com/…Komara
There is an overall design decision by AEM + Dispatcher which allows devs to control cache ability while designing endpoints, and that decision is to couple caching to certain URL styles, such as deciding that suffix is never cached by reverse proxy dispatcher. Therefore if you somehow configure to cache suffix, you're breaking a convention and will confuse other AEM devs to join your projectFibre

© 2022 - 2024 — McMap. All rights reserved.