title: Browser tries to reload same resource several times even when status is 200
body: <p>My application is trying to reload same resource several times but still resource is correctly loaded and status is 200. Application is trying to load <em><a href="http://localhost:8080/scripts/app.js?_=1487686739222" rel="nofollow noreferrer">http://localhost:8080/scripts/app.js?_=1487686739222</a></em> and <em><a href="http://localhost:8080/scripts/vendor.js?_=1487686739293" rel="nofollow noreferrer">http://localhost:8080/scripts/vendor.js?_=1487686739293</a></em> until browser doesn't stop with error. I tried disable cache but it still happens. When I try to load that resource manually resource is loaded correctly. I can't understand what is going wrong why should browser try to reload same resource several times. I'm using Spring and have this kind of configuration for loading <strong><em>index.html</em></strong></p>
  
  <pre><code>@Configuration
  public class WebMvcConfig extends WebMvcConfigurerAdapter {
  
      private String apiPath;
  
      private final ResourceProperties resourceProperties;
  
      @Autowired
      public WebMvcConfig(ResourceProperties resourceProperties) {
          this.resourceProperties = resourceProperties;
      }
  
      public WebMvcConfig(String apiPath, ResourceProperties resourceProperties) {
          this(resourceProperties);
          this.apiPath = apiPath;
      }
  
      private String getApiPath() {
          return apiPath;
      }
  
      @Override
      public void addResourceHandlers(ResourceHandlerRegistry registry) {
          registry
              .addResourceHandler("/app/**", "/pages/**", "/components/**", "/sample", "/")
              .addResourceLocations(resourceProperties.getStaticLocations())
              .setCachePeriod(resourceProperties.getCachePeriod()).resourceChain(true)
              .addResolver(new SinglePageAppResourceResolver());
      }
  
      private class SinglePageAppResourceResolver extends PathResourceResolver {
  
          @Override
          protected Resource getResource(String resourcePath, Resource location) throws IOException {
              Resource resource = location.createRelative(resourcePath);
              if (resource.exists() &amp;&amp; resource.isReadable()) {
                  return resource;
              } else if (getApiPath() != null &amp;&amp; ("/" + resourcePath).startsWith(getApiPath())) {
                  return null;
              } else {
                  resource = location.createRelative("index.html");
                  return (resource.exists() &amp;&amp; resource.isReadable()) ? resource : null;
              }
          }
  
      }
  
  }
  </code></pre>
  
  <p>this is my security configuration:</p>
  
  <pre><code>@Configuration
  @EnableWebSecurity
  public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  
      @Override
      protected void configure(HttpSecurity http) throws Exception {
          http
              .csrf()
              .disable()
              .authorizeRequests()
              .antMatchers("/api/public/**", "/app/**", "/pages/**", "/components/**", "/sample", "/apple-icon.png", "/favicon.ico", "/index.html", "/", "/scripts/**", "/styles/**")
              .permitAll()
              .anyRequest()
              .authenticated()
              .and()
              .formLogin()
              .loginPage("/pages/auth")
              .loginProcessingUrl("/api/public/auth")
              .permitAll()
              .and()
              .logout()
              .permitAll()
              .and()
              .exceptionHandling()
              .authenticationEntryPoint(new Http403ForbiddenEntryPoint());
      }
  
  }
  </code></pre>
  
  <p>this is general data from request in chrome:</p>
  
  <pre><code>Request URL:http://localhost:8080/scripts/app.js?_=1487687587847
  Request Method:GET
  Status Code:200 
  </code></pre>
  
  <p>Also here is console output:</p>
  
  <pre><code>Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
  Tried to load angular more than once.
  </code></pre>