Jahia in English > Custom static asset...

0 (0 Good)
0 (0 Bad)

Custom static asset folder?

by  hchingwong@gmail.com »  2016/05/22 00:34

I'm using bower to manage both Javascript and CSS file as bower components. So both types of file sit under "TEMPLATE_MODULE/src/main/resources/bower_components" directory.

Is there a way I can served my custom folder along with the default javascript and css folders?

I located the coresponding filter and servlet for static assets but am having trouble finding an easy extention point, and I don't know if messing core modules is recommended:

    core/src/main/java/org/jahia/services/render/filter/StaticAssetsFilter.java  &
    core/src/main/java/org/jahia/services/content/files/StaticFileServlet.java

 

If I were to just put my static resources and bower_components directory into tomcat's ROOT directory can you also suggest the path/ mapping as well as a way to properly bypass the url rewrites rules, it seemed like all my requests are redirecting to the /cms/** address.

  • Custom static asset folder?
    2016/05/22 00:35

    hchingwong@gmail.com <p>I&#39;m using bower to manage both Javascript and CSS file as bower components. So both types of file sit under &quot;TEMPLATE_MODULE/src/main/resources/bower_components&quot; directory.</p> <p>Is there a way I can served my custom folder along with the default javascript and css folders?</p> <p>I located the coresponding filter and servlet for static assets but am having trouble finding an easy extention point, and I don&#39;t know if messing core modules is recommended:</p> <blockquote> <p>&nbsp;&nbsp;&nbsp; core/src/main/java/org/jahia/services/render/filter/StaticAssetsFilter.java&nbsp; &amp;<br /> &nbsp;&nbsp;&nbsp; core/src/main/java/org/jahia/services/content/files/StaticFileServlet.java</p> </blockquote> <p>&nbsp;</p> <p>If I were to just put my static resources and bower_components directory into tomcat&#39;s ROOT directory can you also suggest the path/ mapping as well as a way to properly bypass the url rewrites rules, it seemed like all my requests are redirecting to the /cms/** address.</p>

  • Number of messages  7
    Registration date May 22, 2016
    0 (0 Good)
    0 (0 Bad)

    Re: Custom static asset folder?

    by  kevan »  2016/05/22 13:01

    Hi,

    Yes there is simple solution to that, in the pom.xml file of your module you can specify folder that are used to served static resources:

    <Jahia-Static-Resources>/css,/icons,/javascript</Jahia-Static-Resources>

    here is an example: https://github.com/Jahia/document-viewer-ee/blob/3c75a20efd5853cdda254077cd6da4c462211edb/pom.xml

    for your need you just have to add the folder bower_components to the list

    <Jahia-Static-Resources>/css,/icons,/javascript,/bower_components</Jahia-Static-Resources>

    Then you can inject your css and js in your components using the jsp tag "template:addResources":

    example for a .js file locate in TEMPLATE_MODULE/src/main/resources/bower_components/angular/angular.js:

    <template:addResources type="js" resources="angular/angular.js"/>

    Best regards,

    Number of messages  4
    Registration date
    Contact
    Share
    Feedback

    Get in touch

    Whether you are a current user or if you are just evaluating Jahia, we are here to help.

    Contact us

    Share this page