How to map buttons on my mouse with AppleScript?
Karabiner, which Joonas suggested, natively has back/forward options for buttons 4 and 5. You do not have to create a xtml file.
The option is under 'pointing device' > 'button to key' > 'use button 4 and 5 as back/forward'.
I have only used it for 30 minutes so far, but it worked straight away by just activating those checkmarks (mouse: ttesports black v2)