What is PhantomJS?
PhantomJS is a command-line tool that generates HTML from a specified URL, without the help of any browser or rendering. Since rendering is not involved, the resultant HTML is generated very quickly.
When scripts related to Diagram are running in the browser, SVG, that is DOM elements, are generated and appended in the corresponding div element. Diagram generated using PhantomJS generates this SVG much faster as rendering is not involved. By generating this SVG in server-side, HTTP request and response time are saved. You can also cache the generated SVG and reuse it for multiple requests.
The following steps are to help you to apply this to render Diagram.
You can generate SVG using PhantomJS in a Command prompt and MVC application. Used here is an MVC application where the command is executed that saves SVG onto the server using PhantomJS.
Scriptfile.js- In this file, when you mention a URL to the page.Open function, it loads the URL and converts it into SVG.
Filename.svg- Defines the name for the generated SVG file.
You can read the generated SVG in server-side and send it to client-side.
In client-side, the SVG from the server is directly appended into client-side DOM and you can hook events to SVG to enable client-side interaction.
You can save the generated SVG into the cache and load the same SVG whenever you require it.
The following code illustrates how to save the generated SVG into the cache.
The following code illustrates how to retrieve the SVG from the cache.
|Article ID:||Published Date:||Last Revised Date:||Platform:||Control:|
|3066||12/31/2014||12/31/2014||ASP.NET MVC (Classic)||Diagram|