spuas
spuas

Reputation: 1693

How to add different Javascript in development and production wicket

I have a wicket application in which I have added the javascript files within the markup html:

<script src="script/jquery.min.js" type="text/javascript"></script>

My javascript files are not placed beside my .java or .html files, they are in different location in the server as can be seen on previous script declaration.

My question is: Is it possible to add these javascript files depending on the application mode? I.E. if the application is in development mode, load one javascript file, if it is in production load this other one.

Thanks!

PS: the idea is to load "min" version on production but the extended files on development so debugging becomes posible

NOTE: Watching different answers here I re-state: the problem is not finding when the wicket app is in development or deployment mode, I know that, but is about how to change html markup or adding different JavaScript resources

Upvotes: 2

Views: 1204

Answers (5)

bernie
bernie

Reputation: 10390

I use this directory layout:

resources
|---JQueryResource.java
|---jquery-1.6.4.js
|---jquery-1.6.4.min.js

With this class:

public class JQueryResource {
    /**
     * Must be called in a RequestCycle.
     * 
     * @return Url for the jQuery library.
     */
    public static String getURL() {
        if (Application.get().usesDevelopmentConfig()) {
            Url url =
                    RequestCycle.get().mapUrlFor(
                            new PackageResourceReference(JQueryResource.class, "jquery-1.6.4.js"),
                            null);
            return url.toString();
        } else {
            Url url =
                    RequestCycle.get().mapUrlFor(
                            new PackageResourceReference(JQueryResource.class,
                                    "jquery-1.6.4.min.js"), null);
            return url.toString();
        }
    }
}

This is how I add the resource to my page.

@Override
public void renderHead(IHeaderResponse a_response) {
    a_response.renderJavaScriptReference(JQueryResource.getURL());
}

Upvotes: 1

osdamv
osdamv

Reputation: 3583

extendig the answer of @rotsch you can do it in wicket 1.5 with :

@Override
public void renderHead(IHeaderResponse response) {
    if(DEVELOPMENT)
        response.renderString("<script type=\"text/javascript\" src=\"url1\"></script>");
    else
            response.renderString("<script type=\"text/javascript\" src=\"url2\"></script>");

}

https://cwiki.apache.org/WICKET/migration-to-wicket-15.html#MigrationtoWicket1.5-RemovedHeaderContributorandfriends.

Upvotes: 2

user425367
user425367

Reputation:

I set a property in a properties file with I add to the path when starting the VM.

Then I do a if else similar to the PHP answer.

Upvotes: 0

jontro
jontro

Reputation: 10628

You could use pack:tag to compress all your resources: http://sourceforge.net/projects/packtag/

In your web.xml/.properties file you can specify whether to pack it or not depending on your production mode.

Upvotes: 0

rotsch
rotsch

Reputation: 1929

You can find out in which mode you are with the following code:

RuntimeConfigurationType.DEPLOYMENT.equals(getApplication().getConfigurationType())

or

RuntimeConfigurationType.DEVELOPMENT.equals(getApplication().getConfigurationType())

Upvotes: 1

Related Questions