A little bit of theory:
1. Each belt tile has 32 slots.
2. Each item takes 9 slots on a belt.
3. Yellow belt advances 1 slot forward every game cycle (2 for red, 3 for blue).
The trick to compress a belt is to put items on every 9'th slot of the belt. This way you will have gaps that are divisble by 9, therefore they can always be filled with items.
To achieve this all your inserters should be enabled once every 9 cycles and offset according to their position along the belt.
You will need a combinator setup that cycles a signal from 0 to 8 every frame and inserter conditions set to 'signal = 32*x mod 9' (where x is belt tile number). The pattern repeats itself every 9 tiles.
Here are the numbers:
This will be a little different for red belt. Because it moves 2 slots a frame the pattern will repeat itself every 18 tiles instead of 9 and inserters can only be placed on tiles with offset divisible by 2.
For blue belt pattern goes back to 9 tiles, but you can only place inserters on tiles with offset divisible by 3.