Yes, extension can be applied before your work visa expires. If you have lived in Indonesia for 3 consecutive years, you may also opt to apply for the permanent resident permit (KITAP) which has a longer validity period of 5 years and renewable.