Continuity over a compact subset of a metric space implies continuity everywhere Let $f: (X, d_X) \rightarrow (Y, d_Y)$ be a function from metric spaces. If $f$ restricted to any compact subset of $X$ is continuous, then $f$ must be continuous everywhere.
Should I proceed with the characterization of continuity that the preimage of a closed set is closed? Except we are working with compact subsets of the domain, not the range, and it is not true that closed sets are mapped to closed sets, so how can I get continuity of $f$ everywhere?
I am also thinking about the fact that compactness is equivalent to sequential compactness in a metric space. Would this help?

Let $C$ be a closed subset of $Y$ and let $x\in\overline{f^{-1}(C)}$.
There exists a sequence $(x_n)$ in $f^{-1}(C)$ that converges to $x$. The set $S=\{x_n:n\ge0\}\cup\{x\}$ is compact, so the restriction of $f$ to $S$ is continuous. Therefore $\lim_{n\to\infty}f(x_n)=f(x)$ and, since $C$ is closed, we have that $f(x)\in C$. Hence $x\in f^{-1}(C)$.
