Java Javascript Compilation Web Filters

Javascript compilation web filters

Лицензия

Лицензия

Группа

Группа

tech.rsqn
Идентификатор

Идентификатор

jjst
Последняя версия

Последняя версия

1.0.7
Дата

Дата

Тип

Тип

jar
Описание

Описание

Java Javascript Compilation Web Filters
Javascript compilation web filters
Ссылка на сайт

Ссылка на сайт

https://github.com/rsqn/jjst
Система контроля версий

Система контроля версий

https://github.com/rsqn/jjst

Скачать jjst

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
javax.servlet : javax.servlet-api jar 4.0.0-b01
org.slf4j : slf4j-api jar 1.7.21

Модули Проекта

Данный проект не имеет модулей.

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

Версии библиотеки

Версия
1.0.7
1.0.6
1.0.5
1.0.4
1.0.1