I would agree with you on limiting immigration from the middle east as we are inviting the enemy to dinner by doing so............But that would not end the problem.
We cannot win this via isolationism...........This is global in nature and we have assets outside this country. In order to safe guard these assets and our people who travel abroad, we must be proactive in policy versus reactive. Which means killing some of these people from time to time. I'm really not into nation building. I don't care what they think of us, as if they hate us today they'll still hate us tomorrow. If we kick ISIL's ass into the infernal regions of hell they can not come back to fight us on another day because they are dead.
Those who we helped save, in Iraq or mainly the kurds will not hate us for killing their enemies on the battlefield. They may not like us after we leave but they may be less inclined to want to conduct terror attacks against us because we saved them.
How many more hate us because we hit ISIL.......how many more would like us for saving them from ISIL.........Is it more........or is it less.................I simply don't know.
A Caliphate is like Communism, a disastrously inefficient way to organize a society. As liberals dream of communism, Muslims dream of a Caliphate. As the fall of the Soviet Union burst the dreams of communists everywhere, the cold reality of the failure of a Caliphate will also put to rest the dreams of Islamic Supremacy. So long as those dreams are thwarted, they will never die. What you're proposing is an eternal war of whack-a-mole.