How to preload freemarker templates? - freemarker

We are using URLTemplateLoader for loading templates hosted on a web server.
My Template engine app is multithreaded.
We do have the template caching 'on' however, if multiple request goes in
HTTP 429 Too Many Requests response
How can we cache the templates before hand?

One workaround I came up with is having one master template having #include all the template and execute the master template with a scheduler when cache expires. This process downloads the cache when it hits the #include in the freemarker template.

You could implement throttling in your TemplateLoader implementation, and set that as the template loader in the Configuration. It should just delegate to another TemplateLoader, but add throttling around it.
Although, it probably would be better if instead the source server (which now gives 429) is more forgiving when it's really just asked to do its duty.

Related

Single SPA integration with server side rendered html pages

I have an application in which UI is rendered on the server-side using Thymeleaf and the backend is in Spring Boot.
Now, we have a requirement to combine this application with another react application. So, it should be like micro frontend architecture.
For this, I am evaluating the framework Single-SPA and seems like a good option when we have separate frontend projects and we need to combine them in one.
Is it possible to integrate the existing SSR pages with Single-SPA?
This should be possible with single-spa-html as long as there is no JavaScript that is dynamically created. Another limitation is that single-spa-html doesn't process <script/> tags due to browser security. If your application can meet those requirements, it should be able to interop with single-spa-html.
single-spa-html allows providing a template asynchronously, so a fetch or ajax call could retrieve the microfrontend template from the backend. Then the corresponding JavaScript is included in the microfrontend instead of script tagged in.
You can also see an example of enhancing a static html mfe with JS here: https://github.com/filoxo/single-spa-html-with-js-example/
Note: I believe we discussed this on the Slack channel but I want to share here for the benefit of the wider single-spa community.

angular ajax routing with express

My understanding (or misunderstanding): I've just started learning the mean stack and i see that a lot of tutorials (most are pretty old) and some template projects (like mean.io) using angular for routing instead of express (about 80% angular routing and 20% express). My understanding of angular routing is that it is suppose to ajax in a template into the ngView which would keep the page from reloading giving me a true single page application.
my setup: So i have express routing all request to the index file and from there i have created routes in angular for all possible request. each request is routed by angular to a jade template file (which i've seen called partials).
The issue: so i thought that angular would be ajaxing in the partial with each request (giving me the benefit of not having the whole page reload) making a true single page application, but what i've found is that because express (or any other web server for that matter) is routing all request to the index file so angular can do it's thing the index file is always reloaded with each request. because of this, I feel like the ajax routing is meaningless. After all, if the index file is always reloaded on each request which in turn reloads the angular files (and all the js and css files called in the head) then there is no real difference between angular routing and express routing coupled with jade template includes.
The question: Is this the way angular routing coupled with express is meant to be set up and suppose to function or am i doing it all wrong (or when using the mean stack, is it more of a personal choice as to which routing to use rather than a distinct advantage/dis-advantage)?
I see what is going on here: the ajax only seems to happen when following a link from within the browser. If you manually modify the url in the browser bar to test the link it will reload everything. Now i feel silly as hell.

Child XML for Joomla Parameters

I'm creating a template with many parameters available in its backend.
Basically I have about 8 blocks in the template structure (index.php) and each block have about 30 options (background, content type, layout, animation etc) so I have about 300 options totally in the template backend. This makes the template backend is loaded very slow when opened or saved.
Is there any native way (I didn't use any template framework) to make all of these 30 options are loaded in the separated / child xml so it will be called by demand (ajax) and the template backend loaded faster? Any other suggestion or advice are welcome
There is no "native" way to do what you want. I do think, however, that Joomla is slow in rendering these XML tags so it might be worth it to check the code that does the rendering and perhaps optimize it.

Static vs. dynamic content in docpad system - how to create dynamic content?

DocPad is described as being comparable to other static site generators, but it is also described as being "not limited to static site generation".
I've been browsing the DocPad website and other documentation and haven't yet been able to find anything that seems to explain how to incorporate dynamic content, and what types of limitations may be involved?
As a relative beginner, I am wondering if anyone can help me better understand the methodology whereby dynamic content would be incorporated into DocPad...? e.g. AJAX, and dynamic server-side scripts for doing things like dynamically loading pictures from Flickr into a webpage when a certain tag is clicked...
Thanks.
So there's a few ways DocPad facilitates dynamic content:
Via the regenerateEvery configuration option. This will regenerate your website every so often you specify. This great when combined with plugins like feedr for pulling in data from remote feed sources (like your latest social activity), as well as repocloner which clones out and keeps a git repository up to date inside your project. The benefit of this option is it's really easy to do and provides the illusion of a dynamic website. For instance the Benjamin Lupton Website applies this method to keep it's statistics on the home page, as well as the social data in the sidebar up to date. Every hour it regenerates with the latest information. Making it fast, and also illusively dynamic.
Via the dynamic meta-data property. When set to to true this tells the DocPad server we should re-render that document on each request, rather than just once. This works great inside the Kitchensink Skeleton for search pages and misc forms. This way is most similar to PHP development.
Via the serverExtend event. This event allows you to hook into and extend the DocPad server, allowing you to add extra server-side logic, handling, etc. Common use cases is to add extra routing to your server to handle route aliases, adding form processing such as a contact form, or to add a RESTULful interface for a Backbone.js application. The DocPad Website uses this to add extra routing and a regenerate post-receive hook for the documentation. The NodeChat Skeleton uses this to add the Socket.io server-side logic.
Via the API. This way is the most involved but can be quite rewarding if you just wish for DocPad to be a small part of an existing node.js application. With this, you can create a DocPad instance in your code and interact with it. The grunt-docs grunt task utilises this :)

How can I exclude pages created from a specific template from the CQ5 dispatcher cache?

I have a specific Adobe CQ5 (5.5) content template that authors will use to create pages. I want to exclude any page that is created from this template from the dispatcher cache. As I understand it currently, the only way I know to prevent caching is to configure dispatcher.any to not cache a particular URL. But in this case, the URL isn't known until a web author uses the template to create a page. I don't want to have to go back and modify dispatcher.any every time a page is created--or at least I want to automate this if there is no other way. I am using IIS for the dispatcher. The reason I don't want to cache the pages is because the underlying JSPs that render the content for these pages produce dynamic content, and the pages don't use querystrings and won't carry authentication headers. The pages will be created in unpredictable directories, so I don't know the URL pattern ahead of time.
How can I configure things so that any page that is created from a certain template will be automatically excluded from the dispatcher cache?
It seems like CQ ought to have some mechanism to respect HTTP response/caching headers. If the HTTP response headers specify that the response shouldn't be cached, it seems like the dispatcher shouldn't cache it--regardless of what dispatcher.any says. This is the CQ5 documentation I have been referencing.
I don't know about the IIS verson of the Dispatcher, but certainly with the Apache module if you add a custom HTTP header "dispatcher: nocache" it will not cache the page in the Dispatcher. You would need to change the code to add this, which would be something like:
request.setHeader("Dispatcher", "nocache");
It might also work as meta tags in the html, but I've not tried this.
This is documented here: http://dev.day.com/content/kb/home/Dispatcher/faq-s/DispatcherNoCache.html
You might use cache control tags in the template's head. See info on PRAGMA and Cache-Control meta tags here: HTTP Cache- Control.

Resources