yellowtree / geoip-detect

Wordpress plugin "Geolocation IP Detection": Provides geographic information detected by an IP adress.
http://wordpress.org/plugins/geoip-detect/
GNU General Public License v3.0
163 stars 38 forks source link

Optimize size of js on frontend, slim version with essentials #225

Closed jurijc closed 1 year ago

jurijc commented 1 year ago

Size of frontend JS is 20.8kb, which is not small and can affect frontend and page load times. Functionality to detect IP GEO is usually needed onload so it can't be deferred and loaded later.

I would suggest to create separate versions depending on what user needs (can be selected in options) and enqueue that exactly version. That could be two versions: 1) slim, just detection of geo (for example country code, or whole geo_info) 2) full (like it is right now)

Maybe there is better solution, for example to have slim JS snippet to get country code of current ip without even using frontend.js ?

Thank you for your plugin!

benjaminpick commented 1 year ago

Interesting idea! The size of the current beta is only 15kb now simply by upgrading the bundler, but you are right, there is much "advanced" functionality here. However, which functionality is "needed" will be different on every website, so I'm not sure this would create more confusion/support requests than help. But I will experiment with this a little and let you know.

(I am also considering making AJAX mode the default in a future major version, so this topic is relevant, yes.)

jurijc commented 1 year ago

Hello Benjamin, great that this idea is on time, thanks for feedback

if you look from side of support requests - then by default it's full version and it's for average user, so nothing would change. For someone who understands there will be option in admin to include only small version. Or pick one of 1-3 versions for general use cases (for example "I need to detect user location using get_info()" and so on, because you have already separated code for each functionality in bundler) Have a great evening

benjaminpick commented 1 year ago

I have committed a "minimal" file now that only has get_info() that has 7.4kB, if I also remove the localStorage cache it's 6.1kB. For what it does, this is still a lot - there is a lot of "syntactic sugar" to make it easier to use. If I leave away the Record class, returning simply the json data, it's 4.4kB (3.1kB without localstorage). Which of the 4 versions would you use?

jurijc commented 1 year ago

I would try 4.4kb version, I think cache is important it's saves ajax call that is much slower than extra 1.3kb.

benjaminpick commented 1 year ago

Note to self, this is what needs to be done before release: