You need to know the rms current flowing through your switch under worst case condtions.
...
Slightly pedantic, but this is quite often not a safe assumption -- what you're basically implying here is that k is always equal to delta on the "Thermal impedance" chart in the datasheet (e.g. figure 2 in
this one), which judging from the graph is certainly not always true! However, it is
close to true
at high switching frequencies. E.g., at 30kHz, 20% duty cycle, you're looking at a thermal impedance 10% higher than you'd expect. Even so, that 10% is eating into your safety factors.
If you can't be bothered reading the graph, you should work by peak current, not RMS current, to be safe. If you have to be wrong, always be wrong on the safe side.
As with all engineering, the question is not minimization, but optimization. Use only the smallest Rds(on) necessary for the application. When switching and conduction losses are about equal, you'll have it right.
Again, slightly pedantic, but it
is actually minimization; but what you're minimizing is total losses (switching + conduction). But you're right, that'll tend to be when they're roughly equal. This is why I wish digikey had an interface to allow you to type in a custom formula to sort by!