Java Javascript Compilation Web Filters

Javascript compilation web filters

License

License

GroupId

GroupId

tech.rsqn
ArtifactId

ArtifactId

jjst
Last Version

Last Version

1.0.7
Release Date

Release Date

Type

Type

jar
Description

Description

Java Javascript Compilation Web Filters
Javascript compilation web filters
Project URL

Project URL

https://github.com/rsqn/jjst
Source Code Management

Source Code Management

https://github.com/rsqn/jjst

Download jjst

How to add to project

<!-- https://jarcasting.com/artifacts/tech.rsqn/jjst/ -->
<dependency>
    <groupId>tech.rsqn</groupId>
    <artifactId>jjst</artifactId>
    <version>1.0.7</version>
</dependency>
// https://jarcasting.com/artifacts/tech.rsqn/jjst/
implementation 'tech.rsqn:jjst:1.0.7'
// https://jarcasting.com/artifacts/tech.rsqn/jjst/
implementation ("tech.rsqn:jjst:1.0.7")
'tech.rsqn:jjst:jar:1.0.7'
<dependency org="tech.rsqn" name="jjst" rev="1.0.7">
  <artifact name="jjst" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.rsqn', module='jjst', version='1.0.7')
)
libraryDependencies += "tech.rsqn" % "jjst" % "1.0.7"
[tech.rsqn/jjst "1.0.7"]

Dependencies

compile (2)

Group / Artifact Type Version
javax.servlet : javax.servlet-api jar 4.0.0-b01
org.slf4j : slf4j-api jar 1.7.21

Project Modules

There are no modules declared in this project.

jjst

Javascript and CSS Runtime Aggregation Compilation Web Filters

What does this do?

  • Aggregates and delivers Javascript sources into a single file at runtime
  • So your aggregation works the same way for dev, test, prod
  • Compiles the aggregated file using clojure
  • Caches the result if you want it to (if compiling - you want this)
  • Injects information, such as variables and constants at runtime
  • Does mostly the same stuff for CSS

Why would I want this?

Compiling and then caching aggregated content at runtime means you can

  • Have exactly the same process run during development as you have in TEST and PROD
  • Can inject information (such as variables and constants) at runtime in each environment
  • Can dynamically enable or disable features using a pragma style profiles
  • Using bare bones simple #includes you can aggregate all your dependencies javascript or css together
  • Which is easy for anyone to understand
  • Easily controls dependency and execution order
  • Don't need any special "file system watcher" in your build system
  • Everything works the same way in every environment
  • Can cache the result for performance in PROD environments

Is there a working sample project that uses this?

on the way

How do I use this?

Add this dependency

 <dependency>
            <groupId>tech.rsqn</groupId>
            <artifactId>jjst</artifactId>
            <version>1.0.4</version>
 </dependency>

Add these servlets to your web xml.

    <servlet>
        <servlet-name>jjs</servlet-name>
        <servlet-class>tech.rsqn.utils.jjst.servlets.JavascriptAggregationServlet</servlet-class>
        <async-supported>false</async-supported>
        <init-param>
            <param-name>baseProfiles</param-name>
            <param-value>nocache,nocompile</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>jjs</servlet-name>
        <url-pattern>/js/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>cssAggregation</servlet-name>
        <servlet-class>tech.rsqn.utils.jjst.servlets.CssAggregationServlet</servlet-class>
        <async-supported>false</async-supported>
        <init-param>
            <param-name>baseProfiles</param-name>
            <param-value>nocache,nocompile</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>cssAggregation</servlet-name>
        <url-pattern>/css/*</url-pattern>
    </servlet-mapping>

Create a javascript file under /js/ in the root of your webapp

    console.log('hello');

Add your script tag relative to the root of your webapp

    <script src="/js/index.js?profiles=this_is_an_example"></script>

How do I?

Aggregate multiple javascript files ?

index.js ->

import {mylib} from 'libs/mylib.js'
import {myapp} from 'apps/myapp.js'

Use profiles ?

    <script src="/js/index.js?profiles=say_hello"></script>   
    console.log('one');
    #ifprofile sayhello
      console.log('hello');  // its better to actually do an #include here
    #endif
    console.log('two');

Prevent Caching and or Compilation ?

    <script src="/js/index.js?profiles=nocache,nocompile"></script>   

Include environment variables in the output ?

    var myConstant ='${SOME_ENV_VAR}';
    console.log('myVar is ' + myConstant );

Try the sample?

mvn tomcat7:run

Aggregate without compile

http://localhost:8080/ or http://localhost:8080/helloworld_nocomile.html

Aggregate with compile

http://localhost:8080/helloworld_comile.html

tech.rsqn

Rogue Squadron

Versions

Version
1.0.7
1.0.6
1.0.5
1.0.4
1.0.1