Wednesday, June 5, 2024
28
rated 0 times [  33] [ 5]  / answers: 1 / hits: 33007  / 15 Years ago, sun, december 27, 2009, 12:00:00

Just curious, whether the Google Maps API v3 javascript be cached on the local server?



Because, sometimes my intranet pages are loading slow because of slower internet connection. Otherwise, it would load the file from local server and slow down only when the map request is made.



I am even ready to run a cron job to update the javascript file once in a while.



Thanks for any input.


More From » google-maps-api-2

 Answers
11

It's impossible as is.



When you request the script from Google, they send headers along the script and those headers contains the no-cache directive.



So if you want them to be cachable, you must create a proxy. Instead of pointing the script src at Google, you point it to your server. Your server then make the call to Google and send the response back to the client.



This way you'll have control over the HTTP header and the caching. You could do caching on the script content as well to make less connections to Google.



I wouldn't advise someone to do it on a production or a mission critical website. All Google APIs are updated frequently and are bound more or less together. If something goes out of synch with something else, you have a hard to track bug on your hands.



Hope that helps.



EDIT: I heard you were putting your scripts in the HEAD section of your document. Maybe thats hurting your perceived page loading time. Try to move the download of the script just before the </body> tag and the map initialization in the onload event of the page.



Mike


[#97980] Wednesday, December 23, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hasancolec

Total Points: 603
Total Questions: 95
Total Answers: 98

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;