The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Using ng-html2js to Convert Templates into JavaScript

Using ng-html2js to Convert Templates into JavaScript

3:39
ng-html2js takes .html templates and converts them into strings stored in AngularJS's template cache. This allows you to bundle all of your templates into a single JavaScript file for simpler deployment and faster loading. John walks through using ng-html2js in the terminal to show what it does, but to integrate with either [gulp](https://www.npmjs.com/package/gulp-ng-html2js) or [grunt](https://www.npmjs.com/package/grunt-html2js), use the tool specific module.
Watch this lesson now
Avatar
egghead.io

ng-html2js takes .html templates and converts them into strings stored in AngularJS's template cache. This allows you to bundle all of your templates into a single JavaScript file for simpler deployment and faster loading. John walks through using ng-html2js in the terminal to show what it does, but to integrate with either gulp or grunt and loading multiple templates look into using the following packages:

Avatar
Andrey

What is an autocompletition plugin for command line You are using?

Avatar
Dmitri

Would you recommend converting all html files to js and putting them into templateCache? Is this usually done for prod deployments or dev environment too? I guess I am still not exactly clear where the value is. Thank you.

P.S. Clicking on green Subscribe button above show an error page.

Avatar
Joel

Would you recommend converting all html files to js and putting them into templateCache? Is this usually done for prod deployments or dev environment too? I guess I am still not exactly clear where the value is. Thank you.

This is generally done in a build step, and I do it for both production and development.

The advantage of this is efficiency. When you have many HTML partials, they each require a single network request to load. By converting them with this tool, you consolidate them into a single file that can be minified and compressed.

In reply to Dmitri
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?