Currently I'm saving a Json object in the url, however once stringified and escaped escapedit get's extremly long:
Example:
"%7B%22glossary%22%3A%7B%22title%22%3A%22example%20glossary%22%2C%22GlossDiv%22%3A%7B%22title%22%3A%22S%22%2C%22GlossList%22%3A%7B%22GlossEntry%22%3A%7B%22ID%22%3A%22SGML%22%2C%22SortAs%22%3A%22SGML%22%2C%22GlossTerm%22%3A%22Standard%20Generalized%20Markup%20Language%22%2C%22Acronym%22%3A%22SGML%22%2C%22Abbrev%22%3A%22ISO%208879%3A1986%22%2C%22GlossDef%22%3A%7B%22para%22%3A%22A%20meta-markup%20language%2C%20used%20to%20create%20markup%20languages%20such%20as%20DocBook.%22%2C%22GlossSeeAlso%22%3A%5B%22GML%22%2C%22XML%22%5D%7D%2C%22GlossSee%22%3A%22markup%22%7D%7D%7D%7D%7D"
(Object from http://json.org/example.html) Code:
var stringifeid = JSON.stringify({
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
var encoded= encodeURIComponent(stringifeid )
"%7B%22glossary%22%3A%7B%22title%22%3A%22example%20glossary%22%2C%22GlossDiv%22%3A%7B%22title%22%3A%22S%22%2C%22GlossList%22%3A%7B%22GlossEntry%22%3A%7B%22ID%22%3A%22SGML%22%2C%22SortAs%22%3A%22SGML%22%2C%22GlossTerm%22%3A%22Standard%20Generalized%20Markup%20Language%22%2C%22Acronym%22%3A%22SGML%22%2C%22Abbrev%22%3A%22ISO%208879%3A1986%22%2C%22GlossDef%22%3A%7B%22para%22%3A%22A%20meta-markup%20language%2C%20used%20to%20create%20markup%20languages%20such%20as%20DocBook.%22%2C%22GlossSeeAlso%22%3A%5B%22GML%22%2C%22XML%22%5D%7D%2C%22GlossSee%22%3A%22markup%22%7D%7D%7D%7D%7D"
Is there a way to make this shorter?
Background:
I'm having a state based application in angular, which uses the routing and a paramter to save it's current state. The state is a object which is then stringified (JSON.stringify(..)
), when the state changes throw browser back, etc, the state is taken form the url, parsed backed and set in the application.
This works fine, however it is sooo long.