[MGNLRES-152] Generate links to resources, and use selectors with ~ to generate farFutureCaching URLs for resources Created: 22/May/15  Updated: 29/Mar/22  Resolved: 23/Jun/15

Status: Closed
Project: Magnolia Resources Module
Component/s: None
Affects Version/s: None
Fix Version/s: 2.4

Type: Bug Priority: Major
Reporter: Magnolia International Assignee: Magnolia International
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to MAGNOLIA-4207 Fix the cache ressources issue. Closed
relates to MAGNOLIA-4520 farFutureCaching and Resource files w... Closed
relates to MAGNOLIA-5712 farFutureCaching and Resource files w... Closed
relates to MAGNOLIA-4160 Allow dots in node names Closed
relates to MAGNOLIA-2343 Replace current implementation for se... Closed
relates to MGNLRES-171 Move Resource and CssFile classes to ... Closed
relates to MGNLSITE-20 Move Resource and CssFile classes fro... Closed
relates to MAGNOLIA-6217 Review names and "duties" of Filters Open
relates to MAGNOLIA-2580 node names: allow dots Closed
causality
is causing MGNLCACHE-106 Remove unnecessary tildeCacheResource... Closed
dependency
is depended upon by MGNLRES-157 Update uses of renamed TemplatingFunc... Closed
is depended upon by MGNLRES-144 Implement new origin-based ResourcesS... Closed
duplicate
is duplicated by MGNLRES-197 FarFuture caching needs rework of the... Closed
Template:
Acceptance criteria:
Empty
Task DoD:
[ ]* Doc/release notes changes? Comment present?
[ ]* Downstream builds green?
[ ]* Solution information and context easily available?
[ ]* Tests
[ ]* FixVersion filled and not yet released
[ ]  Architecture Decision Record (ADR)
Bug DoR:
[ ]* Steps to reproduce, expected, and actual results filled
[ ]* Affected version filled
Date of First Response:
Team: Nucleus

 Description   

The model class used for resources (info.magnolia.module.resources.Resource) currently generates its "far future caching" links with dots, e.g /resources/foo/bar.2015-05-22-16-00-35-123.cache.css.

This is then "converted" to using ~ by a virtual URI configured in the cache module, which was added via MAGNOLIA-4207 (SCRUM-699).

Finally, the RepositoryMappingFilter strips out the ~ from the current uri set in AggregationState, and sets handle and currentNode.

While convoluted, this works, as long as we load resources after this filter, e.g with the rendering mechanism and the special Resource*Renderers.

If we serve resources via a Servlet, the current uri in AggregationState still has ~'s in it, since servlets are interrupting the filter chain before it reaches the RepositoryMappingFilter. Besides, using a servlet has the added benefit that we can use pathInfo (as opposed to the complete URI, which includes the path to the servlet).

Suggested approach:

  • fix info.magnolia.module.resources.Resource: use ~ directly, no reason to use .
  • remove now-unnecessary virtual uri mapping from cache module (see MGNLCACHE-106)
  • future: review filter chain. RepositoryMappingFilter and a few other filters have responsibilities that belong somewhere, and/or are simply wrongly named. See MAGNOLIA-6217.

Essentially, this is all due to MAGNOLIA-2343, which we've ignored until now.

Meanwhile, we should also factor out the far-future-link generation:

  • info.magnolia.module.resources.servlets.ResourcesServlet#stripFarFutureCachingTimestamp
  • info.magnolia.module.resources.Resource.getLink()
  • info.magnolia.cms.util.LinkUtil has the methods we want but is unused except in DefaultImageProvider (which is probably a good thing, because neither name nor location of this class are good)

We'll also need to investigate browser cache, i.e /modules/cache/config/configurations/default/browserCachePolicy/policies/farFuture/voters/dotCacheExtension



 Comments   
Comment by Magnolia International [ 03/Jun/15 ]

Started work on feature/MGNLRES-152-links

Comment by Magnolia International [ 09/Jun/15 ]

Pushed, cleaned up and squashed on feature/MGNLRES-152-links-3 branch.

Comment by Magnolia International [ 12/Jun/15 ]

The info.magnolia.module.resources.Resource and info.magnolia.module.resources.CssFile classes will be moved to the site module where they belong (next to Site- and Theme- definitions), possibly renamed to something like Site/Page/ResourceDefinition.

The resources module now provides a ResourceLinker, which is used by the above and by the ResourcesServlet; this new component is able to provide links (URLs) from a ResourcePath as well as decode them.

We've also made the ResourcesServlet a SelfMappingServlet, so the mapping is configured in the resources module and can be used to generate links.

Comment by Magnolia International [ 18/Jun/15 ]

see MGNLRES-171 and MGNLSITE-20 for the move/rename of Resource and CssFile

Comment by Philip Mundt [ 23/Jun/15 ]

ResourceLinker needs to use a Provider for the ResourceModule (in ctor) in order to prevent:

info.magnolia.jcr.node2bean.Node2BeanException: com.google.inject.ProvisionException: Guice provision errors:

1) Module instance for module [resources] not available, most likely because the module has not yet been started. Inject a Provider<> instead to get access to the module instance when it's available.
  at info.magnolia.objectfactory.guice.GuiceComponentConfigurationModule.bindProvider(GuiceComponentConfigurationModule.java:190)
  while locating info.magnolia.module.resources.ResourcesModule
    for parameter 1 at info.magnolia.module.resources.ResourceLinker.<init>(ResourceLinker.java:73)
  at info.magnolia.objectfactory.guice.GuiceComponentConfigurationModule.bindImplementation(GuiceComponentConfigurationModule.java:158)
  while locating info.magnolia.module.resources.ResourceLinker
Comment by Magnolia International [ 23/Jun/15 ]

Indeed; we now inject a Provider<ResourcesModule> in ResourceLinker. This is due to the rendering module, which initializes template definitions. Some definitions use ResourceLinker indirectly. The rendering module currently can't depend on resources-module (circular dep with templating)

Generated at Mon Feb 12 06:47:54 CET 2024 using Jira 9.4.2#940002-sha1:46d1a51de284217efdcb32434eab47a99af2938b.