I have a Spring Boot project which hosts several APIs and some simple web pages.
My project is built using Maven by Jenkins.
I'm using ThymeLeaf as my HTML templating tool for the few web pages that I have.
But I'm having issues integrating a tool to minimize my JS and CSS files.
I would like to have my JS and CSS files as full fat files in my src directory but upon compilation, I would like to have the JS and CSS files minimized and references to the full/fat files updated in the thymeleaf html files.
Edit
To those marking my question down and voting to close it, why not post a comment explaining why?
This is a valid request and if you don't know the answer, go find another question to answer to build up your rep points.
Related
I am building an application with react+grails, where grails is the wrapper. However, the react application is based on Create React App, due to this the output template of react is index.html. However, grails don't allow rendering .html files. So, is there anyway to use thymeleaf instead of gsp ?
I have other ways like render text: htmlText, contentType:"text/html", encoding:"UTF-8" but this seems very hacky.
So, is there anyway to use thymeleaf instead of gsp ?
Yes. One way to do that is to use the Spring Boot Thymeleaf support.
However, grails don't allow rendering .html files
That isn't true. We render .html files all the time. You can render any static file from a Grails app, including .html files.
EDIT:
See the project at github.com/jeffbrown/ganeshkhadkahtml.
If you run that app and send a request to http://localhost:8080/showMeSomeHtml that will render the HTML file at src/main/webapp/static/index.html.
You could also send a request to http://localhost:8080/static/index.html to render that same file if you wanted to support that.
I have a main module C-portlet that contains in the folder resources a pdf file.
resources/webapp/files/cg.pdf
I have a war theme. In one of its jsp page, i need to add a link for the cg.pdf.
For now, i have :
<a target="_blank" href="/o/Cportlet/src/main/resources/META-INF/resources/webapp/files/cg.pdf"><liferay-ui:message key="cg-link"/></a>
but it doesn't work.
Last point, this pdf could be changed at anytime without a deploy again a module / war.
Is anyone have an idea ?
Thanks
You can put your pdf file in one of your theme resource folders (for example the "templates" folder).
Now you can use themeDisplay.getPathThemeTemplates() + "/cg.pdf" or within your theme with freemarker "${templates_folder}/cg.pdf"
There are several ways to do this: imagining you cannot use the regular documents library... Or you module cannot use the library to get resources..
You could use a resource action if you have an MVC portlet. This would be the simplest way to just serve that resource, and you would only need to put the MVC resource command URL in you jsp. Regular portlets can also provide resources but not as easily.
For general modules you can create a struts action..which are normally way more complicated, especially if the resource is for private use only.
Go easy please, I'm rather new to the whole web development thing and I'm a little perplexed.
I have the Spark framework installed from Maven, which has Jetty as its underlying web/application server, correct? Jetty is embedded in the Spark jar so I can't/shouldn't mess with it. Is that correct so far?
I read that Spark's embedded Jetty should support rendering of JSP files, however my browser is literally interpreting my JSP pages as text documents. How do I tell Spark/Jetty that it needs to interpret and serve these pages as opposed to just serving them as is?
I'm using Spark 2.5 and the velocity template engine.
Very minimal code so far. Rather than setting up a route to my JSP file I've just been typing the path into my browser while Jetty is running.
I've tested several different minimal JSP files this way.
I added a route in Spark to my JSP file and lo and behold, now it attempts to render the file! I suppose Spark has to handle the interpretation of the string passed to it and Jetty simply serves the content? Beats me! It works!
EDIT: Sorry to bring this back from the dead, but it doesn't have an answer yet and clarity was asked for so.... I added the route using the spark framework in my program, and used the render() function of spark to have Jetty render the JSP file. I had previously been entering the path of the JSP file as a static file, and so Jetty was not interpreting the contents of the file server side (as you would do with JSP) but instead trying to hand the file itself over to the client's browser. Rookie mistake!
Here is my situation: I'm working with an application that makes heavy use of JSP includes <%include ... %> and also loads tons of components dynamically using AJAX. All these get loaded into one main template page depending on what the user selects, etc.
My issue is with editing/maintaining these small page fragments that get included and loaded through AJAX. Since they are fragments, their code does not include a and doesn't include things like JQuery, which are added by the main template page.
Of course when they are loaded in the browser they work since the fragments are loaded through AJAX and added to the DOM.
The issue is: since these are just fragments, when I'm maintaining these pages I get a lot of errors and warnings on missing CSS classes and Javascript variables, etc. Besides, I can't use any WYSIWYG editors for the fragments due to the missing imports.
How can I tell Eclipse to assume certain imports (e.g. JQuery or CSS sheets)for these fragment files? Since using JSP templates is such a common design pattern I can't believe I'm the only person needing this.
You can go to the
Eclipse - > Preferences - > JavaScript - > Include Path -> User Libraries
and add a new JavaSCript library.
You can give your project JS folder .
After that you can go to your project build path and include that library in build path.
or you can add it directly to your project from here,
I understand that it's a GWT, but if it compiles to Javascript, can the generated html module compile to such a packaging that I can just deploy it on Apache, assuming I don't have any backend communications?
Yes. This is basically what I was getting at with this question. For the HTML port, you are effectively building a GWT application, which is just an HTML page hosting a bunch of cleverly obfuscated Javascript.
You can find the relevant Google documentation here:
How do I change the location of my cache/nocache HTML files?