  Let $\Omega $ be an open subset of $\mathbb{R}^{N}$, and let $p,\, q:\Omega
\rightarrow \left[ 1,\infty \right] $ be measurable functions. We give a
necessary and sufficient condition for the embedding of the variable exponent
space $L^{p(\cdot )}\left( \Omega \right) $ in $L^{q(\cdot )}\left( \Omega
\right) $ to be almost compact. This leads to a condition on $\Omega, \, p$ and
$q$ sufficient to ensure that the Sobolev space $W^{1,p(\cdot )}\left( \Omega
\right) $ based on $L^{p(\cdot )}\left( \Omega \right) $ is compactly embedded
in $L^{q(\cdot )}\left( \Omega \right) ;$ compact embedding results of this
type already in the literature are included as special cases.
