Every repository with this icon (
Every repository with this icon (
optimize your response time
This is only for the pure.render.
The pure.autoRender needs the data to compile the template and is most of the time very quick for regular templates.
But in extreme cases, with big templates with a lot of classes, you may need to optimize your rendering time and prefer to use the pure.render
Optimisation 1:
compile your HTML template and give it a name
When you run the pure.render, PURE compiles the HTML to a javascript function.
The time PURE takes to render your template is a compilation time + a running time.
If you plan to use several times the same HTML template in a page it may be a good idea to compile this HTML and give it a name.
You can then reference its name instead of the HTML when you use the render method?.
Here’s an example:
To compile a template
$('ul#nav').compile('myMenu', directive);
This command:
- takes the html from ul#nav
- converts it to a JS function
- and stores it in the $p object under the reference ‘myMenu’
To render the template:
$('ul#nav').render(context, 'myMenu');
This command:
- get the JS function ‘myMenu’
- run this function on the context data
- replace ul#nav by the result
Although it is very short for regular HTML templates, you’ll then save the compilation overhead.
Optimisation 2:
compile, give a name and save the result in a js file
All the examples we provide are compiled on the fly, when you render them.
The time taken to transform is equal to the compilation time + the rendering time.
This compilation takes some time. Although it is very short, you may want to suppress this processing time in your production system.
It is possible to compile all the HTMLs and then save them as JS functions in a javascript file.
Once you have this .js file you can add it to your page using the <script> tag
By doing this you:
- Remove all the js commands related to the directives. And save the time spent on compiling.
- Save some Kb: The js file will be cached and you can remove the pure.js file from your page if you do not have to compile any template on the fly.
Download the source files and locate the page docs/howToCompile.html






