https://github.com/pocesar/angular-save-content
Save the content of a part of your server rendered HTML, so it won't issue an AJAX call to fetch the templateUrl
https://github.com/pocesar/angular-save-content
Last synced: about 1 year ago
JSON representation
Save the content of a part of your server rendered HTML, so it won't issue an AJAX call to fetch the templateUrl
- Host: GitHub
- URL: https://github.com/pocesar/angular-save-content
- Owner: pocesar
- License: mit
- Created: 2015-01-28T12:05:13.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-01-28T12:23:19.000Z (over 11 years ago)
- Last Synced: 2024-10-18T06:28:39.413Z (over 1 year ago)
- Language: JavaScript
- Size: 121 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# angular-save-content
A directive that will save the content of a part of your server rendered HTML, so it won't issue an AJAX call to fetch the templateUrl along side ui-view or ng-view
## Usage
```js
angular
.module('yourapp', ['saveContent'])
.config(['$stateProvider', function($stateProvider){
$stateProvider.state('index', {
url: '/',
templateUrl: 'template.html'
});
});
```
```html
Hi, I was rendered at page load on the server and will stick around while the router path doesn't change
```
This will save the inner HTML of the ui-view to `$templateCache` as `template.html`, saving you another round-trip to the server
You can save multiple snippets of already HTML placed on the page, instead of relying on `` like menus, asides, widgets that were rendered when the page loaded.
## Why?
When using ng-view, ui-view along with templateUrl or ng-include, angular will issue an AJAX call to fetch the content for that view. When you are creating an hybrid page, that mix 'turbo links', many SPA views and server rendered content, you'll end up with the first load of the page already loaded inside ng-view / ui-view, so you don't need it for fetchin g the content that is already visible on the page, and usually refetching it will cause a flicker. So you save the content you already have to the templateCache, so it won't create another get request to the server.
## License
MIT