Search in sources :

Example 1 with FilenameWithVersionResourceCachingStrategy

use of org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy in project oc-explorer by devgateway.

the class FormsWebApplication method optimizeForWebPerformance.

/**
 * optimize wicket for a better web performance This will be invoked if the
 * application is started with -Dwicket.configuration=deployment
 */
private void optimizeForWebPerformance() {
    // add javascript files at the bottom of the page
    setHeaderResponseDecorator(new RenderJavaScriptToFooterHeaderResponseDecorator("scripts-bucket"));
    // The default is Development, so this code is not used
    if (usesDeploymentConfig()) {
        getResourceSettings().setCachingStrategy(new FilenameWithVersionResourceCachingStrategy("-v-", new CachingResourceVersion(new Adler32ResourceVersion())));
        getResourceSettings().setJavaScriptCompressor(new GoogleClosureJavaScriptCompressor(CompilationLevel.SIMPLE_OPTIMIZATIONS));
        getResourceSettings().setCssCompressor(new YuiCssCompressor());
        getFrameworkSettings().setSerializer(new DeflatedJavaSerializer(getApplicationKey()));
        getMarkupSettings().setStripComments(true);
    } else {
        getResourceSettings().setCachingStrategy(new NoOpResourceCachingStrategy());
    }
    getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);
}
Also used : FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) RenderJavaScriptToFooterHeaderResponseDecorator(de.agilecoders.wicket.core.markup.html.RenderJavaScriptToFooterHeaderResponseDecorator) DeflatedJavaSerializer(org.apache.wicket.serialize.java.DeflatedJavaSerializer) NoOpResourceCachingStrategy(org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy) Adler32ResourceVersion(de.agilecoders.wicket.core.request.resource.caching.version.Adler32ResourceVersion) GoogleClosureJavaScriptCompressor(de.agilecoders.wicket.extensions.javascript.GoogleClosureJavaScriptCompressor) CachingResourceVersion(org.apache.wicket.request.resource.caching.version.CachingResourceVersion) YuiCssCompressor(de.agilecoders.wicket.extensions.javascript.YuiCssCompressor)

Example 2 with FilenameWithVersionResourceCachingStrategy

use of org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy in project ocvn by devgateway.

the class FormsWebApplication method optimizeForWebPerformance.

/**
 * optimize wicket for a better web performance This will be invoked if the
 * application is started with -Dwicket.configuration=deployment
 */
private void optimizeForWebPerformance() {
    // add javascript files at the bottom of the page
    setHeaderResponseDecorator(new RenderJavaScriptToFooterHeaderResponseDecorator("scripts-bucket"));
    // The default is Development, so this code is not used
    if (usesDeploymentConfig()) {
        getResourceSettings().setCachingStrategy(new FilenameWithVersionResourceCachingStrategy("-v-", new CachingResourceVersion(new Adler32ResourceVersion())));
        getResourceSettings().setJavaScriptCompressor(new GoogleClosureJavaScriptCompressor(CompilationLevel.SIMPLE_OPTIMIZATIONS));
        getResourceSettings().setCssCompressor(new YuiCssCompressor());
        getFrameworkSettings().setSerializer(new DeflatedJavaSerializer(getApplicationKey()));
        getMarkupSettings().setStripComments(true);
    } else {
        getResourceSettings().setCachingStrategy(new NoOpResourceCachingStrategy());
    }
    getRequestCycleSettings().setRenderStrategy(RenderStrategy.ONE_PASS_RENDER);
}
Also used : FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) RenderJavaScriptToFooterHeaderResponseDecorator(de.agilecoders.wicket.core.markup.html.RenderJavaScriptToFooterHeaderResponseDecorator) DeflatedJavaSerializer(org.apache.wicket.serialize.java.DeflatedJavaSerializer) NoOpResourceCachingStrategy(org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy) Adler32ResourceVersion(de.agilecoders.wicket.core.request.resource.caching.version.Adler32ResourceVersion) GoogleClosureJavaScriptCompressor(de.agilecoders.wicket.extensions.javascript.GoogleClosureJavaScriptCompressor) CachingResourceVersion(org.apache.wicket.request.resource.caching.version.CachingResourceVersion) YuiCssCompressor(de.agilecoders.wicket.extensions.javascript.YuiCssCompressor)

Example 3 with FilenameWithVersionResourceCachingStrategy

use of org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy in project wicket by apache.

the class ResourceSettings method getCachingStrategy.

/**
 * gets the resource caching strategy
 *
 * @return strategy
 */
public IResourceCachingStrategy getCachingStrategy() {
    if (resourceCachingStrategy == null) {
        final IResourceVersion resourceVersion;
        if (application.usesDevelopmentConfig()) {
            // development mode:
            // use last-modified timestamp of packaged resource for resource caching
            // cache the version information for the lifetime of the current http request
            resourceVersion = new RequestCycleCachedResourceVersion(new LastModifiedResourceVersion());
        } else {
            // deployment mode:
            // use message digest over resource content for resource caching
            // cache the version information for the lifetime of the application
            resourceVersion = new CachingResourceVersion(new MessageDigestResourceVersion());
        }
        // cache resource with a version string in the filename
        resourceCachingStrategy = new FilenameWithVersionResourceCachingStrategy(resourceVersion);
    }
    return resourceCachingStrategy;
}
Also used : FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) RequestCycleCachedResourceVersion(org.apache.wicket.request.resource.caching.version.RequestCycleCachedResourceVersion) IResourceVersion(org.apache.wicket.request.resource.caching.version.IResourceVersion) LastModifiedResourceVersion(org.apache.wicket.request.resource.caching.version.LastModifiedResourceVersion) CachingResourceVersion(org.apache.wicket.request.resource.caching.version.CachingResourceVersion) MessageDigestResourceVersion(org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion)

Example 4 with FilenameWithVersionResourceCachingStrategy

use of org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy in project wicket by apache.

the class BasicResourceReferenceMapperTest method versionStringInResourceFilename.

/**
 */
@Test
public void versionStringInResourceFilename() {
    final IStaticCacheableResource resource = new IStaticCacheableResource() {

        private static final long serialVersionUID = 1L;

        @Override
        public Serializable getCacheKey() {
            return null;
        }

        @Override
        public IResourceStream getResourceStream() {
            return new StringResourceStream("foo-bar");
        }

        @Override
        public void respond(Attributes attributes) {
        }

        @Override
        public boolean isCachingEnabled() {
            return true;
        }
    };
    IResourceCachingStrategy strategy = new FilenameWithVersionResourceCachingStrategy("-version-", new AlphaDigitResourceVersion("foobar"));
    INamedParameters params = new PageParameters();
    ResourceUrl url = new ResourceUrl("test.js", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-foobar.js", url.getFileName());
    strategy.undecorateUrl(url);
    assertEquals("test.js", url.getFileName());
    url = new ResourceUrl("test", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-foobar", url.getFileName());
    strategy.undecorateUrl(url);
    assertEquals("test", url.getFileName());
    // this behavior is o.k. since a browser could request an
    // previous version of the resource. for example we
    // could first have 'test-alpha.txt' which would be later replaced
    // by 'test-beta.txt' but in any case will point to
    // internal resource 'test.txt'
    url = new ResourceUrl("test-version-older.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version-.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version--------", params);
    strategy.undecorateUrl(url);
    assertEquals("test", url.getFileName());
    // weird but valid
    url = new ResourceUrl("test-version-1.0.3-alpha.txt", params);
    strategy.undecorateUrl(url);
    assertEquals("test.txt", url.getFileName());
    // check a version that contains a dot which also marks the filename
    // extension
    strategy = new FilenameWithVersionResourceCachingStrategy("-version-", new StaticResourceVersion("1.0.4-beta"));
    url = new ResourceUrl("test.txt", params);
    strategy.decorateUrl(url, resource);
    assertEquals("test-version-1.0.4-beta.txt", url.getFileName());
}
Also used : IStaticCacheableResource(org.apache.wicket.request.resource.caching.IStaticCacheableResource) FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) INamedParameters(org.apache.wicket.request.mapper.parameter.INamedParameters) StaticResourceVersion(org.apache.wicket.request.resource.caching.version.StaticResourceVersion) StringResourceStream(org.apache.wicket.util.resource.StringResourceStream) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IResourceCachingStrategy(org.apache.wicket.request.resource.caching.IResourceCachingStrategy) ResourceUrl(org.apache.wicket.request.resource.caching.ResourceUrl) Test(org.junit.Test)

Example 5 with FilenameWithVersionResourceCachingStrategy

use of org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy in project wicket by apache.

the class ResourceMapperWithDecoratedResourcesTest method newApplication.

@Override
protected WebApplication newApplication() {
    return new MockApplication() {

        @Override
        public void init() {
            super.init();
            getResourceSettings().setCachingStrategy(new FilenameWithVersionResourceCachingStrategy(new CachingResourceVersion(new MessageDigestResourceVersion())));
            mountResource("stylesheet.css", new CssResourceReference(ResourceMapperWithDecoratedResourcesTest.class, "decorated-resource.css"));
            mountPage("/", HomePage.class);
        }
    };
}
Also used : FilenameWithVersionResourceCachingStrategy(org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy) MockApplication(org.apache.wicket.mock.MockApplication) CachingResourceVersion(org.apache.wicket.request.resource.caching.version.CachingResourceVersion) MessageDigestResourceVersion(org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion) CssResourceReference(org.apache.wicket.request.resource.CssResourceReference)

Aggregations

FilenameWithVersionResourceCachingStrategy (org.apache.wicket.request.resource.caching.FilenameWithVersionResourceCachingStrategy)6 CachingResourceVersion (org.apache.wicket.request.resource.caching.version.CachingResourceVersion)4 MessageDigestResourceVersion (org.apache.wicket.request.resource.caching.version.MessageDigestResourceVersion)3 RenderJavaScriptToFooterHeaderResponseDecorator (de.agilecoders.wicket.core.markup.html.RenderJavaScriptToFooterHeaderResponseDecorator)2 Adler32ResourceVersion (de.agilecoders.wicket.core.request.resource.caching.version.Adler32ResourceVersion)2 GoogleClosureJavaScriptCompressor (de.agilecoders.wicket.extensions.javascript.GoogleClosureJavaScriptCompressor)2 YuiCssCompressor (de.agilecoders.wicket.extensions.javascript.YuiCssCompressor)2 MockApplication (org.apache.wicket.mock.MockApplication)2 IStaticCacheableResource (org.apache.wicket.request.resource.caching.IStaticCacheableResource)2 NoOpResourceCachingStrategy (org.apache.wicket.request.resource.caching.NoOpResourceCachingStrategy)2 ResourceUrl (org.apache.wicket.request.resource.caching.ResourceUrl)2 DeflatedJavaSerializer (org.apache.wicket.serialize.java.DeflatedJavaSerializer)2 Session (org.apache.wicket.Session)1 Request (org.apache.wicket.request.Request)1 Response (org.apache.wicket.request.Response)1 INamedParameters (org.apache.wicket.request.mapper.parameter.INamedParameters)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1 CssResourceReference (org.apache.wicket.request.resource.CssResourceReference)1 IResourceCachingStrategy (org.apache.wicket.request.resource.caching.IResourceCachingStrategy)1 IResourceVersion (org.apache.wicket.request.resource.caching.version.IResourceVersion)1