Showing posts with label browser-cache. Show all posts
Showing posts with label browser-cache. Show all posts

Monday, March 21, 2016

404 errors after redeploy webapp minified (caching)

Leave a Comment

I'm facing the fallowing problem with my webapp: every time I have to redeploy it (AWS), the page does not load correctly the first time because (I believe) the local cache has js and css files corresponding to the previously deploy. I'm using Angular backed up by Java and serving with Spring Boot.

This is the state the page looks like

When I foce a re-download (Ctrl + R, e.g.), everything works fine. In a attempt to fix this I added the following meta to my index.html:

<!--Setting the content to "0" tells the browsers to always load the page from the web server.-->   <meta http-equiv="cache-control" content="max-age=0"/>   <meta http-equiv="cache-control" content="no-cache"/>   <meta http-equiv="expires" content="0"/>   <meta http-equiv="expires" content="0"/>   <meta http-equiv="pragma" content="no-cache"/> 

Which apparently did not work. What can I do?

3 Answers

Answers 1

Maybe you can cheat this behaviour by adding a query to your files, somethink like :

<script src="myscript.js?build=mybuildversion"></script> <link href="mystyles.css?build=mybuildversion" rel="stylesheet"> 

Answers 2

You do not need to instruct the browser not to clear the cache for your index.html file. Rather its the CSS files which are being cache. However its not a recommended practice to clear the cache for static resources like images or css files. Rather these files should be cached for long periods to save bandwidth. If you want to force the browser to get a latest version of your static resources you need to make use of the Spring VersionResourceResolver strategy. https://dzone.com/articles/2-step-resource-versioning-with-spring-mvc or http://www.slideshare.net/rstoya05/resource-handling-spring-framework-41

Answers 3

I agree with @Rogerio Soares - your minified scripts should contain a unique identifier for each iteration they go through, whether it be in the filename or in the querystring that accompanies the path/url. This can be taken care of in the grunt/gulp build process.

Read More

Tuesday, March 15, 2016

How to encrypt a pouchdb database

Leave a Comment

Background:

I am trying to encrypt a pouchdb database by using crypto-pouch library. I had a look at the example shown at https://github.com/calvinmetcalf/crypto-pouch But it doesn't seem to do anything for me.

My code:

<!DOCTYPE html>  <html ng-app="pouchdbApp">   <head>     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>     <script src="pouchdbDemo.js"></script>     <script src="http://cdn.jsdelivr.net/pouchdb/5.2.1/pouchdb.min.js"></script>     <!-- <script src="crypto-pouch-master/bundle.js"></script> -->     <script src="http://wzrd.in/standalone/crypto-pouch"></script>       <script>         var db = new PouchDB('kittens2');           var password = "mypassword";          db.crypto(password).then(function (publicKey) {              console.log("publicKey");     	    console.log(publicKey);         });              /* db.removeCrypto();  */           var doc = {  		  "_id": "mittens",  		  "name": "Mittens",  		  "occupation": "kitten",  		  "age": 3,  		  "hobbies": [  		    "playing with balls of yarn",  		    "chasing laser pointers",  		    "lookin' hella cute"   		   ]  		};                db.put(doc);          db.get('mittens').then(function (doc) {           console.log(doc);        });       </script>     </head>   <body>     </body>    </html>

But my code doesn't see to do any encryption of the data entered, or i couldn't see any public key generated.

Any clue how i should be using the crypto-pouch library with pouchdb.

1 Answers

Answers 1

so the documentation is a bit confusing (which I just cleaned up) but when you call db.crypto it wraps the database so that documents are transparently encrypted and decrypted

db.crypto(password).then(function () {    // <-- encryption set up }) 

and it will transparently encrypt documents you create and decrypt ones you read until you call

db.removeCrypto(); 

so if you want to test do something like

db.crypto(password).then(function () {    return db.put({_id: 'foo', bar: 'baz'}); }).then(function () {     return db.get('foo'); }).then(function (doc) {     console.log('decrypted', doc);     return db.removeCrypto(); }).then(function () {     return db.get('foo'); }).then(function (doc) {     console.log('encrypted', doc); }) 
Read More