Home Web Front-end JS Tutorial How to clear browser cache in angularJs

How to clear browser cache in angularJs

Jun 23, 2018 pm 05:31 PM
angularjs browser cache

This article mainly introduces the method of clearing the browser cache in angularJs. The editor thinks it is quite good. Now I will share it with you and give it as a reference. Let’s follow the editor and take a look

Caching

A cache is a component that can store data transparently so that it can serve requests faster in the future. . Obtaining resources repeatedly may cause data duplication and consume time. Therefore, caching is suitable for some data with little variability. The more requests the cache can serve, the more the overall system performance can be improved.

Browser cache, sometimes we need it, because it can improve website performance and browser speed, and improve website performance. But sometimes we have to clear the cache, because the cache may cause problems and some erroneous data may appear. For example, stock websites are updated in real time. Such websites do not need to be cached. Some websites are rarely updated, so it is better to have cache.

The following is the traditional method of clearing the browser

meta method

//不缓存 
<META HTTP-EQUIV="pragma" CONTENT="no-cache">  
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">  
<META HTTP-EQUIV="expires" CONTENT="0">
Copy after login

Clear the temporary cache of the form

<body onLoad="javascript:document.yourFormName.reset()">
Copy after login

ajax clear cache

$.ajax({ 
   url:&#39;www.haorooms.com&#39;, 
   dataType:&#39;json&#39;, 
   data:{}, 
   cache:false,  
   ifModified :true , 
 
   success:function(response){ 
     //操作 
   } 
   async:false 
 });
Copy after login

Use random numbers. Random numbers are also a very good way to avoid caching!

Add "?ran=" Math.random(); //Of course the parameter ran here can be chosen arbitrarily

Use random time, the same as random number.

Add "?timestamp=" new Date().getTime(); after the URL parameters

Use php backend to clean up

Add header("Cache-Control: no-cache, must-revalidate"); and so on on the server side (such as in php)

The following is an introduction to the method of clearing the browser in the angularJs project. Of course, the above traditional method is It is also applicable, but for angularJs, the following items need to be added:

1. Clear the template cache

.run(function($rootScope, $templateCache) {  
      $rootScope.$on(&#39;$routeChangeStart&#39;, function(event, next, current) {  
        if (typeof(current) !== &#39;undefined&#39;){  
          $templateCache.remove(current.templateUrl);  
        }  
      });  
    });
Copy after login

2. Add random parameters to html

.state("content", { 
        url: "/", 
        views:{ 
          "bodyInfo":{templateUrl: &#39;tpls/bodyInfo.html?&#39;+ +new Date(), 
            controller:&#39;bodyInfoCtrl&#39;}, 
          "header":{templateUrl: &#39;tpls/header.html?&#39;+ +new Date(), 
            controller:&#39;headerCtrl&#39; 
          }, 
          "footer":{templateUrl: &#39;tpls/footer.html?&#39;+ +new Date(), 
            controller:&#39;footerCtrl&#39; 
          } 
        } 
      })
Copy after login
<link rel="stylesheet" href="stylesheets/main.css?version=1.0.3" rel="external nofollow" >
Copy after login

3. Clear the route cache

.config([&#39;$stateProvider&#39;, &#39;$urlRouterProvider&#39;,&#39;$locationProvider&#39;,&#39;$httpProvider&#39;,function($stateProvider, $urlRouterProvider,$locationProvider,$httpProvider) { 
//     $urlRouterProvider.when("", "/home"); 
      $urlRouterProvider.otherwise(&#39;/&#39;); 
       if (!$httpProvider.defaults.headers.get) { 
       $httpProvider.defaults.headers.get = {}; 
      } 
      $httpProvider.defaults.headers.common["X-Requested-With"] = &#39;XMLHttpRequest&#39;; 
      $httpProvider.defaults.headers.get[&#39;Cache-Control&#39;] = &#39;no-cache&#39;; 
      $httpProvider.defaults.headers.get[&#39;Pragma&#39;] = &#39;no-cache&#39;;
Copy after login

Okay...that’s all

If there are other methods, please give me some advice !

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to implement circular references between components in Vue.js

There are examples of asynchronous components in Vue

How to solve the maximum call stack error in nodejs

How to implement the blog management platform in Vue SpringBoot

The above is the detailed content of How to clear browser cache in angularJs. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to display all cached DNS entries on Windows 11 How to display all cached DNS entries on Windows 11 May 21, 2023 pm 01:01 PM

The Windows operating system uses a cache to store DNS entries. DNS (Domain Name System) is the core technology of the Internet used for communication. Specifically the IP address used to look up domain names. When a user types a domain name into their browser, one of the first tasks performed when a site loads is to find its IP address. This process requires access to a DNS server. Typically, the Internet Service Provider's DNS servers are used automatically, but administrators may switch to other DNS servers because they may be faster or provide better privacy. Switching DNS providers may also help bypass Internet censorship if DNS is used to block access to certain sites. Windows uses DNS solution

How to clear cache on Windows 11: Detailed tutorial with pictures How to clear cache on Windows 11: Detailed tutorial with pictures Apr 24, 2023 pm 09:37 PM

What is cache? A cache (pronounced ka·shay) is a specialized, high-speed hardware or software component used to store frequently requested data and instructions, which in turn can be used to load websites, applications, services, and other aspects of the system faster part. Caching makes the most frequently accessed data readily available. Cache files are not the same as cache memory. Cache files refer to frequently needed files such as PNGs, icons, logos, shaders, etc., which may be required by multiple programs. These files are stored in your physical drive space and are usually hidden. Cache memory, on the other hand, is a type of memory that is faster than main memory and/or RAM. It greatly reduces data access time since it is closer to the CPU and faster compared to RAM

How to clear cache quickly in Windows 11 How to clear cache quickly in Windows 11 Apr 13, 2023 pm 05:46 PM

For those of you who are not familiar with the term, clearing cache simply means clearing it, and this article will show you how to do it easily in Windows 11. If you're still wondering what cache files are, you should know that it's not as technical as it sounds. Thinking about computers, caches are non-permanent files (or files) that may be needed again in the future. Therefore, the cache remains hidden until that time arrives, thus protecting the content. Caching files is important, but they also take up valuable space. This can be a problem if your SSD has limited capacity. However, there is some good news. Therefore, in most cases, cache files can be safely wiped to clear disk space. Important to Clear Windows 11 Cache

How to clear Safari cache to optimize Mac and iPhone performance? How to clear Safari cache to optimize Mac and iPhone performance? Apr 22, 2023 pm 07:49 PM

Safari's cache makes browsing faster, but it can be buggy, slow down your Mac, iPhone, or iPad, and it can also take up a lot of storage space. Here's how and when to clear it. Like all web browsers, Safari stores data on your Mac, iPhone, and iPad with the express purpose of speeding up your online life. You might have the kind of internet speed you take for granted at Apple Park, but even then, it's best to use that speed where you need it. So when you revisit a website, Safari will try its best to allow you to download only the content that has changed. Even if a news website is updated all day long, the basic layout, furniture of the page

The latest 5 angularjs tutorials in 2022, from entry to mastery The latest 5 angularjs tutorials in 2022, from entry to mastery Jun 15, 2017 pm 05:50 PM

Javascript is a very unique language. It is unique in terms of the organization of the code, the programming paradigm of the code, and the object-oriented theory. The issue of whether Javascript is an object-oriented language that has been debated for a long time has obviously been There is an answer. However, even though Javascript has been dominant for twenty years, if you want to understand popular frameworks such as jQuery, Angularjs, and even React, just watch the "Black Horse Cloud Classroom JavaScript Advanced Framework Design Video Tutorial".

How to clear browser cache How to clear browser cache Jan 09, 2024 pm 05:33 PM

Methods to clear browser cache: 1. Manually clean; 2. Use browser settings to clean; 3. Use third-party tools to clean; 4. Clean regularly; 5. Manually delete cache files; 6. Use browser extensions to clean; 7 , disable browser cache; 8. Manually delete cookies and cookie-related files. Detailed introduction: 1. Manual cleaning, open the browser, press Ctrl+Shift+Delete keys on the keyboard, in the pop-up dialog box, select the "Clear browsing data" option, and select the time range to be cleared, etc.

iPhone & iPad: How to clear cache, history, and cookies iPhone & iPad: How to clear cache, history, and cookies Apr 14, 2023 pm 03:37 PM

How to clear cache on iPhone and iPad in Safari and other apps Open Safari Open Settings Swipe down and tap Safari Swipe down again and tap Clear History and Website Data Tap again to confirm Alternatively, if you want to clear an individual Without clearing the entire Safari cache, select Advanced > Website Data > Edit at the very bottom of Safari settings (or swipe from right to left to delete individual items). Keep in mind that website data deleted from your iPhone or iPad will be deleted from other Apple devices you are signed into the same iCloud account if they are synced with Safari. Clear i

Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Use PHP and AngularJS to build a responsive website to provide a high-quality user experience Jun 27, 2023 pm 07:37 PM

In today's information age, websites have become an important tool for people to obtain information and communicate. A responsive website can adapt to various devices and provide users with a high-quality experience, which has become a hot spot in modern website development. This article will introduce how to use PHP and AngularJS to build a responsive website to provide a high-quality user experience. Introduction to PHP PHP is an open source server-side programming language ideal for web development. PHP has many advantages, such as easy to learn, cross-platform, rich tool library, development efficiency

See all articles