fingerprint-plugin

Plugin for web resources optimization

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.aerse.maven
ArtifactId

ArtifactId

fingerprint-maven-plugin
Last Version

Last Version

3.6
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

fingerprint-plugin
Plugin for web resources optimization
Project URL

Project URL

https://github.com/dernasherbrezon/fingerprint-maven-plugin
Source Code Management

Source Code Management

https://github.com/dernasherbrezon/fingerprint-maven-plugin

Download fingerprint-maven-plugin

How to add to project

<plugin>
    <groupId>com.aerse.maven</groupId>
    <artifactId>fingerprint-maven-plugin</artifactId>
    <version>3.6</version>
</plugin>

Dependencies

compile (6)

Group / Artifact Type Version
commons-codec : commons-codec jar 1.10
commons-io : commons-io jar 2.7
org.apache.commons : commons-text jar 1.6
com.yahoo.platform.yui : yuicompressor jar 2.4.8
org.apache.maven : maven-plugin-api jar 3.0.5
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.2

test (1)

Group / Artifact Type Version
junit : junit jar 4.13.1

Project Modules

There are no modules declared in this project.

fingerprint-maven-plugin Build Status Quality Gate Status

Maven plugin for web resources optimization

About

This plugin performs several optimizations:

  • Resource fingerprinting.
  • JS/CSS minification. yuicompressor is used
  • html minification.

Fingerprinting

During this process plugin calculates file checksum and prepends it to the file name. All links to this filename will be changed to the fingerprinted version. Original file will be deleted. Fingerprinting used to improve web resource caching. If file checksum is not changed, then the name will be the same and it is safe to add max expires header. Once file contents are changed, checksum will be changed as well. This plugin filters out (recursivly) source directory, detects any resources using the patterns below and copy result (if needed) to the target directory.

The following patterns are used to detect resources eligible for fingerprinting:

  • <link.*?href="(.*?)".*?>
  • "([^\\s]*?\\.js)"
  • <img.*?src="(.*?)".*?>
  • url\("(.*?)"\)
  • (<c:url.*?value=\")(/{1}.*?)(\".*?>)

After fingerprinting it is safe to add max expires header.

Requirements

  • All resources should have absolute paths:
    • Valid: <img src="/img/test.png">
    • Invalid: <img src="test.png">
  • All resources should point to existing files without any pre-processing:
    • Valid: <img src="/img/test.png">
    • Invalid: <img src="<c:if test="${var}">/img/test.png</c:if>"

HTML minification

During html minification:

  • all space between tags will be removed. Except pre.
  • type="text" will be removed from input tags since it's default type.

Configuration

  • Configure plugin in pom.xml:
			<plugin>
				<groupId>com.aerse.maven</groupId>
				<artifactId>fingerprint-maven-plugin</artifactId>
				<version>3.6</version>
				<executions>
					<execution>
						<phase>package</phase>
						<goals>
							<goal>generate</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<excludeResources>
						<excludeResource>://</excludeResource>
						<excludeResource>//</excludeResource>
						<excludeResource>data:</excludeResource>
					</excludeResources>
<!-- ${basedir}/src/main/webapp by default -->
					<sourceDirectory>${basedir}/target/webcombined</sourceDirectory>
<!-- ${project.build.directory}/optimized-webapp by default -->
					<targetDirectory>${basedir}/target/optimized-webapp</targetDirectory>
<!-- Remove unnecessary spaces between tags. Make single line page. Takes into consideration <pre> tags -->
					<htmlExtensions>
						<htmlExtension>html</htmlExtension>
						<htmlExtension>jsp</htmlExtension>
						<htmlExtension>tag</htmlExtension>
					</htmlExtensions>
					<extensionsToFilter>
						<extensionToFilter>html</extensionToFilter>
						<extensionToFilter>jsp</extensionToFilter>
						<extensionToFilter>tag</extensionToFilter>
						<extensionToFilter>css</extensionToFilter>
						<extensionToFilter>js</extensionToFilter>
					</extensionsToFilter>
<!-- cdn host. Not required. For example using "//accountname.r.worldssl.net": /css/bootstrap.css -> //accountname.r.worldssl.net/css/<md5>bootstrap.css -->
					<cdn>${cdn}</cdn>
<!-- fingerprinted filename. Could be [name].[ext]?hash=[hash] -->
					<namePattern>[hash][name].[ext]</namePattern>
				</configuration>
			</plugin>
  • Configure apache or nginx with max expires header. The following example is the configuration for nginx:
        location ~ ^/.+\.(ico|jpg|jpeg|gif|pdf|jar|png|js|css|txt|epf|ttf|svg|woff)$ {
            root         <your root content>;
            expires max;
            add_header Cache-Control public;
        }

Versions

Version
3.6
3.5
3.4
3.3