Giter Site home page Giter Site logo

gitter-badger / spring-angular-cache-preloader Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lukashinsch/spring-angular-cache-preloader

0.0 1.0 0.0 174 KB

Component to pre-fill caches for angular js rest request though index page

License: MIT License

HTML 100.00%

spring-angular-cache-preloader's Introduction

spring-angular-cache-preloader

Component to pre-fill caches for angular js rest request though index page

Overview

This component can be hooked into a Spring WebMVC application to tunnel REST requests that a single page app makes on first page load through the index page and prefill angular's $http cache with the values.

How to use

Gradle dependency

compile('eu.hinsch:spring-angular-cache-preloader:0.2.0')

Maven dependency

<dependency>
  <groupId>eu.hinsch</groupId>
  <artifactId>spring-angular-cache-preloader</artifactId>
  <version>0.2.0</version>
</dependency>

Configure resource transformer

public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
    @Autowired
    private AngularRestCachePreloadTransformer angularRestCachePreloadTransformer;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/index.html", "/") // or whatever your welcome page is
                .addResourceLocations("classpath:/location-of-index/")
                .resourceChain(false)
                .addTransformer(angularRestCachePreloadTransformer);
    }
}

Placeholder for generated script

Add {cachePreloadScript} in your index.html (right before the end tag), this will be replaced by <script>...</script>

Turn on caching for request in angular

For example, if you are using ng-resource then you can turn on caching for a request by

$resource('some-url', {}, {
    query : {
        method : 'GET',
        cache : true,
        isArray: true
    }})
    .query();

Configure urls to cache

In application.yml

cache-preload:
  # name of some existing angular module in your app that is being loaded
  angular-module: myapp
  
  cached-urls:
    # static url to be cached (must be the same as configured in $resource)
    - url: some-url
    
    # dynamic url, where the parameter (likely) to be used is known/can be guessed by server
    - url: some-dynamic-url/{some-param}
      parameters:
        # any SpEL expression (with access to any bean)
        some-param: my-expression

Example

See test/java/eu/hinsch/spring/angular/cache/test/TestApplication.java, test/resources/application.yml and test/resources/web/index.html for details.

spring-angular-cache-preloader's People

Contributors

lukashinsch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.