001// Copyright 2011 The Apache Software Foundation 002// 003// Licensed under the Apache License, Version 2.0 (the "License"); 004// you may not use this file except in compliance with the License. 005// You may obtain a copy of the License at 006// 007// http://www.apache.org/licenses/LICENSE-2.0 008// 009// Unless required by applicable law or agreed to in writing, software 010// distributed under the License is distributed on an "AS IS" BASIS, 011// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 012// See the License for the specific language governing permissions and 013// limitations under the License. 014 015package org.apache.tapestry5.services.assets; 016 017import java.io.IOException; 018 019import org.apache.tapestry5.ioc.annotations.Primary; 020import org.apache.tapestry5.ioc.annotations.UsesMappedConfiguration; 021 022/** 023 * Certain kinds of resources can be minimized: this primarily refers to JavaScript and CSS, both of which contain 024 * whitespace, comments and other features that can be reduced. 025 * <p> 026 * The service configuration maps a MIME content type (e.g., "text/javascript") to an appropriate implementation of this 027 * interface. The master service has the @{@link Primary} marker interface. 028 * 029 * @since 5.3 030 */ 031@UsesMappedConfiguration(ResourceMinimizer.class) 032public interface ResourceMinimizer 033{ 034 /** 035 * Checks the {@linkplain StreamableResource#getContentType() content type} of the resource and applies an 036 * appropriate minimization to it if possible. 037 * 038 * @param resource 039 * to minimize 040 * @return the same resource, or a minimized replacement for the resource 041 * @throws IOException 042 */ 043 StreamableResource minimize(StreamableResource resource) throws IOException; 044}