Multi-access edge computing (MEC) is a key technology in the fifth generation (5G) of mobile networks. MEC optimizes communication and computation resources by hosting the application process close to the user equipment (UE) in network edges. The key characteristics of MEC are its ultra-low latency response and real-time applications in emerging 5G networks. However, one of the main challenges in MEC-enabled 5G networks is that MEC servers are distributed within the ultra-dense network. Hence, it is an issue to manage user mobility within ultra-dense MEC coverage, which causes frequent handover. In this study, our purposed algorithms include the handover cost while having optimum offloading decisions. The contribution of this research is to choose optimum parameters in optimization function while considering handover, delay, and energy costs. In this study, it assumed that the upcoming future tasks are unknown and online task offloading (TO) decisions are considered. Generally, two scenarios are considered. In the first one, called the online UE-BS algorithm, the users have both user-side and base station-side (BS) information. Because the BS information is available, it is possible to calculate the optimum BS for offloading and there would be no handover. However, in the second one, called the BS-learning algorithm, the users only have user-side information. This means the users need to learn time and energy costs throughout the observation and select optimum BS based on it. In the results section, we compare our proposed algorithm with recently published literature. Additionally, to evaluate the performance it is compared with the optimum offline solution and two baseline scenarios. The simulation results indicate that the proposed methods outperform the overall system performance.