Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of ContextEngine is hardcoded into DXA #111

Open
willprice76 opened this issue Aug 23, 2018 · 1 comment
Open

Use of ContextEngine is hardcoded into DXA #111

willprice76 opened this issue Aug 23, 2018 · 1 comment

Comments

@willprice76
Copy link
Contributor

The ContextEngine is used to determine device characteristics such as screen width and device family. This is then used in the DefaultMediaHelper and ContextualDeviceUrlBasedViewResolver to implement serverside responsive (RESS) rendering.

Some rough tests I have done for a page (without any caching) give a processing time of 2.2 seconds with the ContextEngine and 1.2 seconds without. Many implementations implement responsive design client side, and would thus prefer not to have this unneccesary overhead on every request.

It would be thus good to have a feature toggle to set use of the ContextEngine on/off.

@willprice76
Copy link
Contributor Author

willprice76 commented Aug 23, 2018

A quick and dirty workaround without rebuilding DXA is to do the following:

  1. Wire in (in a Spring initialization class) a standard ViewResolver before the ContextualDeviceUrlBasedViewResolvers kick in
@Bean
    public ViewResolver fallbackViewResolver() {
        UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix(this.viewResolverPrefix);
        viewResolver.setSuffix(this.viewResolverSuffix);
        viewResolver.setOrder(5);//before the 2 ContextualDeviceUrlBasedViewResolvers (order 10 and 20)
        return viewResolver;
    }
  1. Make your own MediaHelper and override the methods which use the context engine:
@Component
@Primary
public class NonResponsiveMediaHelper extends DefaultMediaHelper {

    //These are the 2 methods that call the context engine in the super class.
    //By overriding them we ensure the Context Engine is never called

    @Override
    public ScreenWidth getScreenWidth() {
        return ScreenWidth.MEDIUM;
    }

    @Override
    public int getResponsiveWidth(String widthFactor, int containerSize) {
        widthFactor = StringUtils.isEmpty(widthFactor) ? "100%" : widthFactor;
        double width = 0.0D;
        if (!widthFactor.endsWith("%")){
            try {
                width = Double.parseDouble(widthFactor);
            } catch (NumberFormatException var11) {
                widthFactor = "100%";
            }
        }
        if (widthFactor.endsWith("%")){
            return super.getResponsiveWidth(widthFactor, containerSize);
        }
        return (int)Math.ceil(width);
    }
}

willprice76 pushed a commit to willprice76/dxa-web-application-java that referenced this issue Oct 1, 2018
…I-3391 to develop

* commit '87d2a873fd4db696126f8cd8b8ae8042e0f254a9':
  TSI-3391 fixed pattern to support "dxa.modules.tridion.docs.properties"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants