I need to remove the script Tapestry adds to the b

2019-08-03 09:17发布

问题:

Yes, I know it is important and Tapestry needs it for its JS support and what not, but I do not use Tapestry JS functionality at all.

I have already managed to remove all the generic CSS and JS that is added by Tapestry, but I cannot find a way to remove this script from the bottom of most pages:

Tapestry.onDOMLoaded(function() {
    //blebleble
});

What I tried is to override the JavaScriptSupport class, providing my own, completely empty implementation. But the script is STILL there! I believe the methods responsible for inserting this script are called addScript() but providing empty implementation for them does not solve the problem.

Part of AppModule:

@Contribute(ServiceOverride.class)
public static void setupApplicationServiceOverrides(
        MappedConfiguration<Class, Object> configuration, ObjectLocator locator)
{
    configuration.add(JavaScriptSupport.class, new JavaScriptSupportOverride());
}

Part of JavaScriptSupportOverride:

@Override
public void addScript(String format, Object... arguments)
{
}

@Override
public void addScript(InitializationPriority priority, String format,
        Object... arguments)
{
}

I need it quite badly and I would be happy to set bounty when SO permits me.

Any insight would be greatly appreciated.

回答1:

This seems like a strange thing to be doing as you'll break everything. But you could do it by removing the "JavaScriptSupport" MarkupRendererFilter from the MarkupRenderer pipeline:

YourAppModule.java

public static void contributeMarkupRenderer(OrderedConfiguration<MarkupRendererFilter> config) {
    config.add("JavaScriptSupport", null);
}

Tapestry uses MarkupRendererFilters to add things like CSS and JS files to the HTML. Download the tapestry sources and take a look at TapestryModule.java. It seems like you might want to remove / tweak some of the core filters which include:

configuration.add("DocumentLinker", documentLinker);
configuration.add("JavaScriptSupport", javaScriptSupport);
configuration.add("RenderSupport", renderSupport);
configuration.add("InjectDefaultStylesheet", injectDefaultStylesheet);
configuration.add("ClientBehaviorSupport", clientBehaviorSupport);
configuration.add("Heartbeat", heartbeat);
configuration.add("ValidationDecorator", defaultValidationDecorator);

* edit *

References to after:* have been changed to before:* (since the first filter also runs last).

Another solution is to let all of the core filters run and contribute your own MarkupRendererFilter which is ordered "before:*". This filter could go through the DOM and remove anything you don't want before it's written to the Response output stream.



标签: tapestry